Browse Source

Removing ssh/telnet/rlogin services due to old syscall dependency

Signed-off-by: Álvaro Jurado <elbingmiss@gmail.com>
Álvaro Jurado 1 year ago
parent
commit
ccdb6fd39c
60 changed files with 2 additions and 23807 deletions
  1. 2 5
      rc/bin/cpurc
  2. 0 174
      sys/man/4/ratfs
  3. 0 536
      sys/man/4/ssh
  4. 0 308
      sys/man/4/webfs
  5. 0 339
      sys/man/4/wikifs
  6. 0 3
      sys/src/cmd/ip/ip.json
  7. 0 52
      sys/src/cmd/ip/rlogind.c
  8. 0 585
      sys/src/cmd/ip/telnet.c
  9. 0 396
      sys/src/cmd/ip/telnet.h
  10. 0 657
      sys/src/cmd/ip/telnetd.c
  11. 0 459
      sys/src/cmd/ssh1/agent.c
  12. 0 47
      sys/src/cmd/ssh1/authpasswd.c
  13. 0 123
      sys/src/cmd/ssh1/authrsa.c
  14. 0 30
      sys/src/cmd/ssh1/authsrvpasswd.c
  15. 0 61
      sys/src/cmd/ssh1/authsrvtis.c
  16. 0 74
      sys/src/cmd/ssh1/authtis.c
  17. 0 55
      sys/src/cmd/ssh1/cipher3des.c
  18. 0 48
      sys/src/cmd/ssh1/cipherblowfish.c
  19. 0 48
      sys/src/cmd/ssh1/cipherdes.c
  20. 0 36
      sys/src/cmd/ssh1/ciphernone.c
  21. 0 53
      sys/src/cmd/ssh1/cipherrc4.c
  22. 0 36
      sys/src/cmd/ssh1/ciphertwiddle.c
  23. 0 384
      sys/src/cmd/ssh1/cmsg.c
  24. 0 78
      sys/src/cmd/ssh1/mkfile
  25. 0 520
      sys/src/cmd/ssh1/msg.c
  26. 0 236
      sys/src/cmd/ssh1/pubkey.c
  27. 0 809
      sys/src/cmd/ssh1/scp.c
  28. 0 294
      sys/src/cmd/ssh1/smsg.c
  29. 0 312
      sys/src/cmd/ssh1/ssh.h
  30. 0 602
      sys/src/cmd/ssh1/ssh1.c
  31. 0 1118
      sys/src/cmd/ssh1/sshnet.c
  32. 0 324
      sys/src/cmd/ssh1/sshserve.c
  33. 0 278
      sys/src/cmd/ssh1/util.c
  34. 0 27
      sys/src/cmd/ssh2/_changes
  35. 0 58
      sys/src/cmd/ssh2/cipher3des.c
  36. 0 100
      sys/src/cmd/ssh2/cipheraes.c
  37. 0 75
      sys/src/cmd/ssh2/cipherblowfish.c
  38. 0 54
      sys/src/cmd/ssh2/cipherrc4.c
  39. 0 39
      sys/src/cmd/ssh2/common.c
  40. 0 960
      sys/src/cmd/ssh2/dh.c
  41. 0 569
      sys/src/cmd/ssh2/dial.c
  42. 0 568
      sys/src/cmd/ssh2/dial.thread.c
  43. 0 3502
      sys/src/cmd/ssh2/dup.out
  44. 0 2668
      sys/src/cmd/ssh2/dup.pro
  45. 0 36
      sys/src/cmd/ssh2/dup.sum
  46. 0 235
      sys/src/cmd/ssh2/dup.xpr
  47. 0 26
      sys/src/cmd/ssh2/esmprint.c
  48. 0 39
      sys/src/cmd/ssh2/funclen
  49. 0 80
      sys/src/cmd/ssh2/long.funcs
  50. 0 5
      sys/src/cmd/ssh2/magic
  51. 0 290
      sys/src/cmd/ssh2/magic.out
  52. 0 75
      sys/src/cmd/ssh2/mkfile
  53. 0 3231
      sys/src/cmd/ssh2/netssh.c
  54. 0 358
      sys/src/cmd/ssh2/netssh.h
  55. 0 235
      sys/src/cmd/ssh2/pubkey.c
  56. 0 75
      sys/src/cmd/ssh2/rsa2ssh2.c
  57. 0 627
      sys/src/cmd/ssh2/ssh2.c
  58. 0 38
      sys/src/cmd/ssh2/ssh2.h
  59. 0 512
      sys/src/cmd/ssh2/sshsession.c
  60. 0 245
      sys/src/cmd/ssh2/transport.c

+ 2 - 5
rc/bin/cpurc

@@ -53,10 +53,8 @@ rm -f '#¤/caphash'
 #	mv /rc/bin/service/tcp567 /rc/bin/service/_tcp567
 # }
 
-# netssh
-
 # start listeners if it hasn't already been done (dicey check)
-if(! netstat -n | grep -s 'tcp.*Listen.* (7|9|21|22|23|25|110|113|565|993|17007|17009|17010) .*')
+if(! netstat -n | grep -s 'tcp.*Listen.* (7|9|21|113|565|17007|17009|17010) .*')
 	aux/listen -q tcp
 
 if(! ps|grep -s timesync) {
@@ -75,8 +73,7 @@ if(test -e /cfg/$sysname/cpustart)
 # other /proc files, such as note, so let listen be killed.
 #dontkill '^(ipconfig|factotum|mntgen|venti|fossil|cs|dns|reboot)$'
 
-#aux/listen1 -t -v tcp!*!1522 /bin/aux/pipeconsole /bin/rc -m /rc/lib/rcmain -i &
-#aux/comconsole '#t/eia0' /bin/rc -m/rc/lib/rcmain -i &
+#aux/listen1 -t -v tcp!*!1522 /bin/rc -m /rc/lib/rcmain -i &
 
 echo 'key proto=p9sk1 dom=harvey user=harvey !password=harvey' >/mnt/factotum/ctl
 aux/listen1 -t tcp!*!6666 /bin/cpu -R &

+ 0 - 174
sys/man/4/ratfs

@@ -1,174 +0,0 @@
-.TH RATFS 4
-.SH NAME
-ratfs  \- mail address ratification file system
-.SH SYNOPSIS
-.B ratfs
-[
-.B -d
-] [
-.B -c
-.I configuration
-] [
-.B -f
-.I classification
-] [
-.B -m
-.I mountpoint
-]
-.SH DESCRIPTION
-.I Ratfs
-starts a process that mounts itself (see
-.IR bind (2))
-on
-.I mountpoint
-(default
-.BR /mail/ratify ).
-.I Ratfs
-is a persistent representation of the local network
-configuration and spam blocking list.  Without it
-each instance of
-.IR smtpd (6)
-would need to reread and parse a multimegabyte list
-of addresses and accounts.
-.PP
-.I Ratfs
-serves a control file,
-.BR ctl ,
-and several top level directories:
-.BR trusted ,
-.BR deny ,
-.BR dial ,
-.BR block ,
-.BR delay ,
-and
-.BR allow .
-.PP
-The control file is write only and accepts three
-possible commands:
-.TF "debug file
-.TP
-.B reload
-rereads
-.I classification
-and
-.I configuration
-.TP
-.B debug \fIfile\fP
-creates
-.I file
-and sends debugging output to it.
-.TP
-.B nodebug
-closes the debug file and turns off debugging
-.PD
-.PP
-The directory
-.B trusted
-serves a file for each IP range from which all mail
-is trusted.  The names of the files are CIDR blocks;
-an IP address or an IP address followed by
-.BR #\fIn\fP ,
-where
-.I n
-is the number of bits to match.
-To check if any IP address falls in a trusted
-range, it is sufficient to open the file whose
-name is the IP address.
-For example, if
-.B trusted
-contains only the file
-.BR 135.104.0.0#16 ,
-an attempt to open the file 135.104.9.1 will
-succeed while opening 10.1.1.1 will fail.
-To determine the particular range matched,
-.B dirfstat
-(see stat (2))
-the open file and the
-.B name
-field will be the matching CIDR range.
-.PP
-The trusted ranges come both from the
-.B ournet
-entries in the file
-.I configuration
-(default
-.BR /mail/lib/blocked )
-and from creates, typically done by
-.B imap4d
-(see
-.IR ipserv (8))
-and
-.B pop3
-(see
-.IR mail (1))
-whenever they are used to read someone's mail.
-.PP
-The remaining directories,
-.BR allow ,
-.BR block ,
-.BR delay ,
-.BR deny ,
-and
-.BR dial ,
-represent the contents of the
-.I classification 
-(default
-.BR /mail/lib/smtpd.conf.ext ).
-Each contains two directories;
-.B ip
-and
-.BR account .
-The
-.B ip
-directory has the same open semantics as the 
-.B trusted
-directory, i.e., to check if an IP address falls
-in that category, try to open a file whose
-name is the IP address.
-The
-.B account
-directory is similar but is used for matching
-strings.  Each file in the directory represents
-a regular expression.  To see if one of the
-strings matches one of the regular expressions,
-try to open the file whose name is the string.
-If it succeeds, then there is a regular expression
-that matches.  To determine the regular expression,
-.B fstat
-the open file.  The
-.B name
-field will be the regular expression.
-.PP
-There is a direct mapping from entries in
-.I classification
-and files under
-.BR allow ,
-.BR block ,
-.BR delay ,
-.BR deny ,
-and
-.BR dial.
-A configuration file entry of the form:
-.EX
-	dial	135.104.9.0/24
-.EE
-corresponds to the file
-.BR dial/ip/135.104.9.0#24 .
-An entry of the form
-.EX
-	*block	.*!gre
-.EE
-corresponds to the file
-.BR block/account/.*!gre .
-.PP
-Both the configuration file and control file formats
-are described in
-.IR smtpd (6).
-.SH SOURCE
-.B /sys/src/cmd/ratfs
-.SH "SEE ALSO"
-.IR mail (1)
-.IR smtpd (6)
-.IR scanmail (8)
-
-

+ 0 - 536
sys/man/4/ssh

@@ -1,536 +0,0 @@
-.TH SSH 4
-.SH NAME
-ssh, netssh \- serve SSH v2 over TCP
-.SH SYNOPSIS
-.B netssh
-[
-.B -9dkv
-] [
-.B -m
-.I mntpt
-] [
-.B -s
-.I srvpt
-]
-.PP
-.2C
-.B "cd /net/ssh"
-.B ./clone
-.B ./ctl
-.B ./keys
-.BI ./ n
-.BI ./ n /clone
-.BI ./ n /ctl
-.BI ./ n /data
-.BI ./ n /listen
-.BI ./ n /local
-.BI ./ n /remote
-.BI ./ n /status
-.BI ./ n /tcp
-\&...
-.BI ./ n / ch
-.BI ./ n / ch /ctl
-.BI ./ n / ch /data
-.BI ./ n / ch /listen
-.BI ./ n / ch /request
-.BI ./ n / ch /status
-\&...
-.1C
-.fi
-.SH DESCRIPTION
-The
-.I netssh
-file server implements SSH v2 over TCP.
-All of the encryption, authentication, and SSH protocol are handled
-by a server managing SSH tunnels
-that appears as a protocol directory,
-.BR /net/ssh ,
-similar to those of
-.IR ip (3)
-but with an extra level of hierarchy for SSH channels within connections.
-Options are:
-.TF -m
-.TP
-.B -d
-Increase the amount of debugging output.
-.TP
-.B -k
-Use
-.IR keyfs (4)
-for password validation.
-.TP
-.B -m
-Mount point for the SSH protocol directory; defaults to
-.BR /net .
-.TP
-.B -s
-Name to post in
-.BR /srv .
-If
-.B -s
-is not given, no file is posted to
-.BR /srv .
-.TP
-.B -v
-Do not verify the remote system's host key (which is somewhat pedantic anyway).
-This lets us talk to SSH v1 systems.
-The presence of
-.B /env/nosshkeyverify
-is equivalent to specifying this option.
-.PD
-.LP
-.B /net/ssh
-contains a set of numbered directories, each of which
-is an SSH connection that is currently active or has been used in the past,
-per
-.IR ip (3).
-Opening
-.B clone
-reserves an SSH connection, reading from
-it returns the connection number reserved, and writing to it writes to the
-.B ctl
-file in the numbered connection directory.
-Reading the
-.B ctl
-file returns the most active state of any connection.
-.B /net/ssh/ctl
-currently implements no commands.
-Finally, the
-.B keys
-file is used by
-.IR ssh2 (1)
-to relay information about keys and passwords between a user and the SSH server.
-.LP
-Each of the numbered connection directories contains
-a set of numbered directories, one for each channel used on
-that connection (see
-.ft B
-Channel Directories
-.ft
-below).
-Similar to the top-level
-.B clone
-file, opening a connection's
-.B clone
-file reserves a channel and gives access to its
-.B ctl
-file.
-Reading from the
-.B ctl
-file returns the connection number (also the name of that directory).
-Commands may be written to a connection's
-.B ctl
-file:
-.TF connect
-.TP
-.B connect
-Dial the remote system and perform the initial
-handshake to exchange versions, lists of supported algorithms,
-and to establish the encryption keys to use.
-.TP
-.B ssh-userauth
-Attempt to authenticate a user with the remote system, with either
-public key authentication or a password.
-.TP
-.B ssh-connection
-Currently unsupported.
-.TP
-.B hangup
-Shut down a connection and all of its channels.
-.TP
-.B announce
-.B /net/ssh
-will accept connection requests from remote systems.
-.TP
-.B accept
-Do the initial connection handshake with the calling system.
-.TP
-.B reject
-Send back a connection rejection message to the caller
-and shut down the connection.
-.PD
-.LP
-Because data is always carried over a channel, the connection data file
-is not used for usual data.
-However, reads from the connection data file do return the capability
-needed for
-.I sshsession
-to change identity to the user logging in.
-As with other protocol directories, opens on
-.B listen
-block until a remote system establishes a connection, at which point,
-a server should write either an
-.B accept
-or
-.B reject
-message to the
-.B ctl
-file.
-The
-.B local
-and
-.B remote
-files give the IP addresses and port numbers of the local and remote
-systems.
-The connection
-.B status
-file gives the status of the most-recently established channel.
-.
-.SS "Channel Directories"
-In each channel directory,
-.BI /net/ssh/ conn / chan\fR,
-reads from channel
-.B ctl
-files return the channel number.
-Commands that may be written to a channel
-.B ctl
-file include:
-.TF connect
-.TP
-.B connect
-Create a new channel over this connection.
-SSHv2 defines
-.BR session ,
-.BR x11 ,
-.BR forwarded-tcpip ,
-and
-.B direct-tcpip
-channels.
-The
-.B connect
-command defaults to a
-.B session
-channel if no argument is given.
-(This implementation correctly handles only session channel requests.)
-.TP
-.B global
-Reserved for future development.
-In particular, this is necessary to support TCP/IP forwarding.
-.TP
-.B hangup
-Shut down a channel.
-If this is the last open channel on this connection, then shut down
-the connection too.
-.TP
-.B announce
-Announce willingness to accept new channel requests from the calling system.
-.PD
-.LP
-The channel
-.B data
-file is the file over which all application data is carried.
-Opens of the channel
-.B listen
-file block until a channel is opened by the remote end.
-Unlike the connection
-.B listen
-file, the listening program should not write an
-.B accept
-or
-.B reject
-message to the
-.B ctl
-file.
-.PP
-SSHv2 defines a number of out-of-band channel requests,
-sent and received through the
-.B request
-file.
-Among these are
-.BR env ,
-.BR exec ,
-.BR exit-signal ,
-.BR exit-status ,
-.BR pty-req ,
-.BR shell ,
-.BR signal ,
-.BR subsystem ,
-.BR window-change ,
-.BR x11-req ,
-and
-.BR xon-xoff .
-.I Sshsession
-only fully handles the
-.B shell
-and
-.B exec
-requests.
-Others are blithely acknowledged, rejected or ignored,
-depending on whether they are expected to be available by
-the remote system.
-.PP
-The channel
-.B status
-file contains one of:
-.BR Empty ,
-.BR Allocated ,
-.BR Initting ,
-.BR Listening ,
-.BR Opening ,
-.BR Negotiating ,
-.BR Authing ,
-.BR Established ,
-.BR Eof ,
-.BR Closing ,
-or
-.BR Closed .
-.
-.SS "Cryptographic Algorithms"
-During the initial connection exchange, both parties send lists of
-supported algorithms.
-The first list is for key exchange;
-we support
-.B diffie-hellman-group1-sha1
-and
-.BR diffie-hellman-group14-sha1 .
-The second list is the set for which corresponding host keys exist;
-we support
-.B ssh-rsa
-and
-.BR ssh-dss .
-The next lists are encryption algorithms, which may be negotiated
-independently for the server-to-client and client-to-server directions;
-we support
-.BR aes128-cbc ,
-.BR aes192-cbc ,
-.BR aes256-cbc ,
-.BR 3des-cbc ,
-and
-.B arcfour
-with preference given in that order.
-The final list is message authentication code algorithms;
-we only support
-.BR hmac-sha1 .
-.
-.SS "Keys and Management"
-Various keys are used by the SSH server.
-Most of them are expected to be stored in the instance of
-.IR factotum (4)
-running in the namespace of that server instance.
-Sometimes there are alternative locations.
-.LP
-The first key needed is the host key for server operation.
-In the case of the keys being stored in
-.IR factotum (4),
-these keys will be the first ones listed with
-.B proto=rsa
-and
-.BR proto=dss .
-Alternatively, these keys can be specified in the environment variables
-.B rsakey
-and
-.B dsskey
-or in files of the same names in the directory where
-.I netssh
-is started.
-.LP
-The next set of keys are the public host keys used by clients to
-verify the identities of servers.
-As with the original Plan 9 SSH implementation,
-there is a system-wide list of these in
-.B /sys/lib/ssh/keyring
-and each user may have a list in
-.BR $home/lib/keyring .
-If a public key for a remote server is listed and matches the one
-offered by the server, the connection proceeds.
-If a public key for a remote server is listed but does not match
-the one offered by the server, or
-if no public key is listed for a remote server,
-.I ssh
-(see
-.IR ssh2 (1))
-presents the key to the user and asks whether to reject the
-key, accept the key only for that session, or accept the key permanently.
-The last option causes the key to be written to the user's keyring.
-In the case of a mismatching key, the accept option can
-either be to add to or replace the old key.
-.LP
-An SSH daemon,
-such as
-.I sshsession
-in
-.IR ssh2 (1),
-must also have a list of public keys
-for public key authentication.
-Again, these keys must be stored in the
-.I factotum
-instance running in the name space of the daemon's SSH server.
-Each such key must have the attributes
-.BR role=verify,
-.BR proto=rsa ,
-and either
-.B user=
-or
-.BR sys= .
-.LP
-The next key is a user's private key to be used for public key authentication.
-We only support RSA keys for this, and the key must be in the
-.I factotum
-instance running in the namespace of the
-.IR ssh (4)
-instance.
-Creating a key and putting it in
-.I factotum
-can be done by:
-.IP
-.EX
-auth/rsagen >key; read -m key >/mnt/factotum/ctl
-.EE
-.LP
-The key file will normally be loaded when
-.I factotum
-is started, either by way of
-.IR secstore (1)
-or directly in the user's
-.BR lib/profile .
-See
-.IR ssh2 (1)
-for
-.IR rsa2ssh2 .
-.LP
-The command
-.IP
-.EX
-auth/pemdecode 'RSA PRIVATE KEY' id_rsa | auth/asn12rsa >key
-.EE
-.LP
-will translate a private key used with OpenSSH to one suitable
-for loading into
-.IR factotum .
-.LP
-To disambiguate when a user has more than one private key stored in
-.IR factotum ,
-the following selection criteria are applied:
-.TF "M."
-.PD 0.2v
-.TP 3
-1.
-The selected key must have both
-.B proto=rsa
-and
-.B !dk=
-attributes present.
-.TP
-2.
-Among those keys, the attributes
-.BR user= ,
-.BR sys= ,
-and any attribute/value pair specified in a
-.B -z
-option to
-.I ssh
-are examined.
-The value of the
-.B user
-attribute is expected to be the user name being authenticated on the remote
-system, and the value of the
-.B sys
-attribute is expected to be the remote system as specified in the
-.I ssh
-invocation.
-.TP
-3.
-The key with the greatest number of matches (most specific match) is selected.
-Among keys with equal number of matches, the first is chosen.
-.PD
-.LP
-For password-based user authentication,
-.I netssh
-can run in one of two modes.
-If given
-.BR -k ,
-it will validate passwords against those stored in
-.B /mnt/keys
-provided by
-.IR keyfs (4).
-If run without
-.BR -k ,
-it will validate passwords with an authentication server using
-.I auth_userpasswd
-in
-.IR auth (2).
-.SH FILES
-.TF /sys/lib/ssh/keyring
-.TP
-.B /sys/lib/ssh/keyring
-System-wide known host public keys.
-.TP
-.B $home/lib/keyring
-Per-user known host public keys.
-.TP
-.B /env/nosshkeyverify
-.SH SOURCE
-.B /sys/src/cmd/ssh2
-.SH "SEE ALSO"
-.IR ssh2 (1),
-.IR ip (3),
-.IR factotum (4),
-.IR keyfs (4),
-.IR authsrv (6),
-.IR dsa (8),
-.IR rsa (8)
-.br
-RFCs 4250, 4251, 4252, 4253, 4254, and 4419
-.SH BUGS
-.I Netssh
-shouldn't have to run as the host owner and using
-.IR factotum (4)
-correctly would permit this.
-.PP
-.I Netssh
-should be simplified by removing the top (connection) level of the
-.B /net/ssh
-hierarchy and multiplexing a single network connection
-after the initial negotiation.
-This would fit better with
-.IR dial (2),
-permit transports other than TCP,
-and allow co-existence of v1 and v2 implementations on a single TCP port.
-Better still,
-use only a single channel (since we don't use X11)
-and eliminate the top 2 levels.
-.PP
-.I Netssh
-authentication via
-.I keyfs
-and public keys uses
-.LR #¤/caphash ,
-which isn't normally present after
-.I cpurc
-runs, so
-.I netssh
-needs to be converted to use
-.IR factotum .
-.PP
-.B netssh
-.B -k
-assumes that
-.I keyfs
-is mounted,
-which is typically only true of authentication servers.
-.PP
-The
-.B keys
-file protocol should be documented.
-.PP
-Only capable of using TCP for underlying connections.
-.PP
-Can't coexist with SSH v1 on the same port.
-.PP
-Several aspects of key management still need some work.
-.PP
-TCP/IP forwarding and some potentially useful channel requests have not
-been implemented.
-.PP
-.B Zlib
-compression is not supported and probably not needed.
-.PP
-The SSH v2 protocol is a classic second system:
-over-engineered,
-overly complicated,
-misdesigned
-and
-jammed full of pointless goodies.
-.PP
-Host key verification is broken, so it's disabled temporarily
-until it's fixed.

+ 0 - 308
sys/man/4/webfs

@@ -1,308 +0,0 @@
-.TH WEBFS 4
-.SH NAME
-webfs \- world wide web file system
-.SH SYNOPSIS
-.B webfs
-[
-.B -c
-.I cookiefile
-]
-[
-.B -m
-.I mtpt
-]
-[
-.B -s
-.I service
-]
-.SH DESCRIPTION
-.I Webfs
-presents a file system interface to the parsing and retrieving
-of URLs.
-.I Webfs
-mounts itself at
-.I mtpt
-(default
-.BR /mnt/web ),
-and, if 
-.I service
-is specified, will post a service file descriptor
-in 
-.BR /srv/\fIservice .
-.PP
-.I Webfs
-presents a three-level file system suggestive
-of the network protocol hierarchies
-.IR ip (3)
-and
-.IR ether (3).
-.PP
-The top level contains three files:
-.BR ctl ,
-.BR cookies ,
-and
-.BR clone .
-.PP
-The
-.B ctl
-file is used to maintain parameters global to the instance of
-.IR webfs .
-Reading the 
-.B ctl
-file yields the current values of the parameters.
-Writing strings of the form
-.RB `` attr " " value ''
-sets a particular attribute.
-Attributes are:
-.TP
-.B chatty9p
-The
-.B chatty9p
-flag used by the 9P library, discussed in
-.IR 9p (2).
-.B 0
-is no debugging,
-.B 1
-prints 9P message traces on standard error,
-and values above
-.B 1
-present more debugging, at the whim of the library.
-The default for this and the following debug flags is 
-.BR 0 .
-.TP
-.B fsdebug
-This variable is the level of debugging output about the file system module.
-.TP
-.B cookiedebug
-This variable is the level of debugging output about the cookie module.
-.TP
-.B urldebug
-This variable is the level of debugging output about URL parsing.
-.TP
-.B acceptcookies
-This flag controls whether to accept cookies presented by remote web servers.
-(Cookies are described below, in the discussion of the
-.B cookies
-file.)
-The values
-.B on
-and
-.B off
-are synonymous with
-.B 1
-and
-.BR 0 .
-The default is
-.BR on .
-.TP
-.B sendcookies
-This flag controls whether to present stored cookies to remote web servers.
-The default is
-.BR on .
-.TP
-.B redirectlimit
-Web servers can respond to a request with a message
-redirecting to another page.
-.I Webfs
-makes no effort to determine whether it is in an infinite
-redirect loop.
-Instead, it gives up after this many redirects.
-The default is
-.BR 10 .
-.TP
-.B useragent
-.I Webfs
-sends the value of this attribute in its
-.B User-Agent:
-header in its HTTP requests.
-The default is
-.RB `` "webfs/2.0 (plan 9)" .''
-.PD
-.PP
-The top-level directory also contains
-numbered directories corresponding to connections, which
-may be used to fetch a single URL.
-To allocate a connection, open the
-.B clone
-file and read a number 
-.I n
-from it.
-After opening, the
-.B clone
-file is equivalent to the file
-.IB n /ctl \fR.
-A connection is assumed closed once all files in its directory
-have been closed, and is then will be reallocated.
-.PP
-Each connection has its own private set of
-.BR acceptcookies ,
-.BR sendcookies ,
-.BR redirectlimit ,
-and
-.B useragent
-variables, initialized to the defaults set in the
-root's
-.B ctl
-file.  The per-connection
-.B ctl
-file allows editing the variables for this particular connection.
-.PP
-Each connection also has a URL string variable
-.B url
-associated with it.
-This URL may be an absolute URL such as
-.I http://www.lucent.com/index.html
-or a relative URL such as
-.IR ../index.html .
-The
-.B baseurl
-string variable sets the URL against which relative URLs
-are interpreted.
-Once the URL has been set,
-its pieces can be retrieved via individual files in the
-.B parsed
-directory.
-.I Webfs
-parses the following URL syntaxes; names in italics are
-the names of files in the
-.B parsed
-directory.
-.IP
-\fIscheme\f5:\fIschemedata
-.br
-\f5http://\fIhost\f5/\fIpath\fR[\f5?\fIquery\fR][\f5#\fIfragment\fR]
-.br
-\f5ftp://\fR[\fIuser\fR[\f5:\fIpassword\fR]\f5@\fR]\fP\f5\fIhost\f5/\fIpath\fR[\f5;type=\fIftptype\fR]
-.br
-\f5file:\fIpath
-.LP
-If there is associated data to be
-posted with the request, it can be written to
-.BR postbody .
-Finally, opening
-.B body
-initiates the request.
-The resulting data may be read from
-.B body
-as it arrives.
-After the request has been executed, the MIME content type
-may be read from the
-.B contenttype
-file.
-.PP
-The top-level
-.B cookies
-file contains the internal set of HTTP cookies, which
-are used by HTTP servers to associate requests with persistent
-state such as user profiles.
-It may be edited as an ordinary text file.
-Multiple instances of
-.I webfs
-and
-.IR webcookies (4)
-share cookies by keeping their internal set
-consistent with the
-.I cookiefile
-(default
-.BR $home/lib/webcookies ),
-which has the same format.
-.PP
-These files contain one line per cookie;
-each cookie comprises some number of
-.IB attr = value
-pairs.
-Cookie attributes are:
-.TP
-.BI name= name
-The name of the cookie on the remote server.
-.TP
-.BI value= value
-The value associated with that name on the remote server.
-The actual data included when a cookie is sent back
-to the server is
-.IB \fR``\fIname = value\fR''
-(where, confusingly,
-.I name
-and
-.I value
-are the values associated with the
-.B name
-and
-.B value
-attributes.
-.TP
-.BI domain= domain
-If
-.I domain
-is an IP address, the cookie can only be used for URLs
-with
-.I host
-equal to that IP address.
-Otherwise,
-.I domain
-must be a pattern beginning with a dot, and
-the cookie can only be used for URLs with a
-.I host
-having
-.I domain
-as a suffix.
-For example, a cookie with
-.B domain=.bell-labs.com
-may be used on hosts
-.I www.bell-labs.com
-and
-.IR www.research.bell-labs.com
-(but not
-.IR www.not-bell-labs.com ).
-.TP
-.BI path= path
-The cookie can only be used for URLs with a path
-beginning with
-.IR path .
-.TP
-.BI version= version
-The version of the HTTP cookie specification, specified by the server.
-.TP
-.BI comment= comment
-A comment, specified by the server.
-.TP
-.BI expire= expire
-The cookie expires at time
-.IR expire ,
-which is a decimal number of seconds since the epoch.
-.TP
-.B secure=1
-The cookie may only be used over secure
-.RB ( https )
-connections.
-Secure connections are currently unimplemented.
-.TP
-.B explicitdomain=1
-The domain associated with this cookie was set by
-the server (rather than inferred from a URL).
-.TP
-.B explicitpath=1
-The path associated with this cookie was set by the
-server (rather than inferred from a URL).
-.TP
-.B netscapestyle=1
-The server presented the cookie in ``Netscape style,'' which
-does not conform to the cookie standard, RFC2109.
-It is assumed that when presenting the cookie to the server,
-it must be sent back in Netscape style as well.
-.PD
-.SH EXAMPLE
-.B /sys/src/cmd/webfs/webget.c
-is a simple client.
-.SH SOURCE
-.B /sys/src/cmd/webfs
-.SH SEE ALSO
-.IR hget (1),
-.IR webcookies (4)
-.SH BUGS
-It's not clear what the relationship between
-.IR hget ,
-.I webcookies
-and
-.I webfs
-should be.

+ 0 - 339
sys/man/4/wikifs

@@ -1,339 +0,0 @@
-.TH WIKIFS 4
-.SH NAME
-wikifs, wikipost \- wiki file system
-.SH SYNOPSIS
-.B wikifs
-[
-.B -DM
-]
-[
-.B -a
-.I announce
-]...
-[
-.B -m
-.I mtpt
-]
-[
-.B -p
-.I perm
-]
-[
-.B -s
-.I service
-]
-.I dir
-.PP
-.B ip/httpd/wikipost
-.RB [ -b
-.IR inbuf ]
-.RB [ -d
-.IR domain ]
-.RB [ -r
-.IR remoteip ]
-.RB [ -w
-.IR webroot ]
-.RB [ -N
-.IR netdir ]
-.I method version uri
-.RI [ search ]
-.SH DESCRIPTION
-A
-.I wiki
-is a web server that facilitates easy editing of the pages it contains.
-.I Wikifs
-presents a wiki in two forms: as web pages to be served
-via
-.IR httpd (8)
-and as text files to be viewed via the
-.IR acme (1)
-wiki client
-(see
-.BR /acme/wiki/guide ).
-.PP
-.I Wikifs
-presents a file system interface to the wiki data stored
-in
-.IR dir .
-By default,
-.I wikifs
-mounts itself at
-.BR /mnt/wiki ;
-the
-.B -m
-flag specifies a different mount point,
-and the
-.B -M
-flag causes
-.I wikifs
-not to mount at all.
-.I Wikifs
-also announces 9P network services on the addresses
-given as arguments to
-.B -a
-options.
-If the
-.B -s
-option is given,
-.I wikifs
-will post a service file descriptor in
-.BI /srv/ service
-with permission
-.I perm
-(default 600).
-The
-.B -D
-flag causes a transcript of the 9P conversation
-to be written to standard error.
-.PP
-The wiki holds both the current pages and also
-all versions of all pages that have ever existed.
-All pages have time stamps associated with them.
-When a user wants to edit a page, he reads the 
-current page from the wiki, noting the time stamp
-on the page.
-When a user writes changes to a page, he includes the time stamp
-of the page he started with.  If the page has been updated
-by someone else while he was editing, the write will fail.
-This is called a ``conflicting write.''
-The submission is still saved in the history, so that
-the user can compare the page he submitted with the changes
-that were made while he was editing.
-.PP
-Each version of each page is described by a text file containing 
-one or more metadata lines followed by the page contents.
-The metadata lines begin with a capital letter specifying the type of data.
-Currently the metadata types are:
-.TP
-.B D
-The date this page was written, in decimal seconds since the epoch.
-.TP
-.B A
-The author of this version of the page.  Typically the rest of the line
-takes the form
-.I name
-.IR ip-address .
-.TP
-.B X
-This page's contents were submitted but rejected due to a
-conflicting write.
-.PD
-.PP
-After the metadata comes the actual page contents; each line of
-page contents is prefixed with a
-.B #
-character.
-.PP
-The directory
-.IB dir /d
-contains all the wiki data.  Typically it is world-writable
-so that
-.I wikifs
-can run as none.
-Each page on the wiki has a unique sequence number
-.IR n ;
-for each page, the
-.B d
-directory contains three files
-.IR n ,
-.IB n .hist \fR,
-and
-.BI L .n \fR.
-The file
-.I n
-holds the current version of the page: the first line of
-.I n
-is the page title, followed by page metadata and contents as described above.
-The append-only file
-.IB n .hist
-holds the history of the page.
-The first line of
-.IB n .hist
-is the title of the page.
-The rest of the file is the metadata and contents of every
-version of the page that has been submitted to the wiki.
-.BI L .n
-is a lock file for the page: it must be 
-held while reading or writing
-.I n
-and
-.IB n .hist \fR.
-The lock files allow multiple instances of
-.I wikifs
-to coexist peacefully.
-Finally, the
-.B map
-file (with associated lock
-.BR L.map )
-provides a mapping from
-sequence numbers to
-to page titles.
-Each map line is a decimal
-.IR n ,
-a single space,
-and then the title.
-Since titles are presented as names by
-.IR wikifs ,
-they cannot contain slashes.
-.PP
-.I Wikifs
-presents a three-level file system.
-The top level contains per-page directories
-named by the page titles with spaces turned
-into underscores.
-Each page also has a number associated with it
-(see the discussion of the wiki data files below).
-The number corresponding to a page may
-also be used to access it, although directory
-listings will always present the title.
-The
-.B new
-file is used to add new or revised pages to the wiki:
-writes to the file should be in the usual textual format:
-a title line, metadata lines, and page contents.
-Once all the contents have been written, a final zero-length
-message should be written to mark the end of the page.
-This last write will return an error if a conflicting
-write has occurred.
-After writing the file, the client may read from
-.B new
-to obtain the canonical title for the page, as presented
-by the file system.
-.PP
-The page directories contain subdirectories representing
-the history of the page, named
-by the decimal time stamp corresponding to each version.
-In addition to these history directories,
-the page directories contain the following files:
-.TP
-.B current
-The current raw data file for the page.
-.TP
-.B diff.html
-A web page listing the contents of every version of
-the page that has ever appeared on the wiki.
-The text is grey by default:
-differences between versions appear in black.
-.TP
-.B edit.html
-A web form for editing the the current version of the page.
-.TP
-.B history.html
-A web page listing the time stamps of the historical versions of the page.
-Each time stamp links to a page showing just
-that version.
-.TP
-.B history.txt
-A textual formatting of the history.  Each time stamp is prefixed with
-the name of the directory corresponding to that version.
-.TP
-.B index.html
-An HTML formatting of the current version of the page.
-.TP
-.B index.txt
-A textual formatting of the current version of the page.
-.TP
-.B werror.html
-An HTML error page to be returned by
-.I wikipost
-on conflicting writes.
-.PD
-.LP
-The HTML files are generated from the templates with the same names
-in
-.IR dir ,
-except that
-.B index.html
-and
-.B index.txt
-are generated from the templates
-.B page.html
-and
-.BR page.txt .
-.PP
-The history directories
-are similar to the page directories but only contain
-.BR current ,
-.BR index.html ,
-and
-.BR index.txt .
-This
-.B index.html
-and
-.B index.txt
-are generated from the templates
-.B oldpage.html
-and
-.BR oldpage.txt .
-.PP
-The
-.IR httpd (8)
-helper program
-.I wikipost
-is used to process editing requests posted
-to the web server by users.
-It expects the posted form to contain these
-(usually hidden) fields:
-.BR TITLE ,
-the title of the page;
-.BR VERSION ,
-the time stamp of the page that is being edited;
-.BR service ,
-the service name associated with this wiki
-.RI ( wikipost
-looks for
-.BI /srv/wiki. service \fR);
-and
-.BR base ,
-the base for wiki URLs in the response.
-.PP
-After mounting the wiki,
-.I wikipost
-writes a page update request to
-.B /mnt/wiki/new
-and then returns the contents of one HTML
-file in
-.BR /mnt/wiki/ title \fR.
-If the write succeeds,
-.I wikipost
-returns
-.BR index.html .
-if the write fails due to a conflicting write,
-.I wikipost
-returns
-.BR werror.html .
-.SH EXAMPLE
-The Plan 9 wiki at Bell Labs is started by running:
-.EX
-.ta +4n
-	wikifs -p 666 -s wiki.plan9 -a tcp!*!wiki /sys/lib/wiki
-.EE
-.PP
-The wiki is mounted for
-.IR httpd (8)
-by an entry in
-.BR /lib/namespace.httpd :
-.EX
-.ta +4n
-	# wiki
-	mount -b #s/wiki.plan9 /usr/web/wiki/plan9
-.EE
-Notice that the wiki service was explicitly posted with
-mode 666 so that
-.I httpd
-(running as none)
-would be able to mount it.
-.PP
-In the Plan 9 distribution, the directory
-.B /sys/lib/wiki
-contains sample files similar to those used
-to start the current Plan 9 wiki.
-.SH SOURCE
-.B /sys/src/cmd/wikifs
-.br
-.B /sys/src/cmd/ip/httpd/wikipost.c
-.SH SEE ALSO
-The original wiki,
-.B http://c2.com/cgi/wiki?WikiWikiWeb
-.br
-.B /acme/wiki/guide

+ 0 - 3
sys/src/cmd/ip/ip.json

@@ -26,9 +26,6 @@
 			"rarpd.c",
 			"rexexec.c",
 			"rip.c",
-			"rlogind.c",
-			"telnet.c",
-			"telnetd.c",
 			"tftpd.c",
 			"traceroute.c",
 			"udpecho.c",

+ 0 - 52
sys/src/cmd/ip/rlogind.c

@@ -1,52 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-
-void	getstr(int, char*, int);
-
-void
-main(void)
-{
-	char luser[128], ruser[128], term[128], err[128];
-
-	getstr(0, err, sizeof(err));
-	getstr(0, ruser, sizeof(ruser));
-	getstr(0, luser, sizeof(luser));
-	getstr(0, term, sizeof(term));
-	write(0, "", 1);
-
-	if(luser[0] == '\0')
-		strncpy(luser, ruser, sizeof luser);
-	luser[sizeof luser-1] = '\0';
-	syslog(0, "telnet", "rlogind %s", luser);
-	execl("/bin/ip/telnetd", "telnetd", "-n", "-u", luser, nil);
-	fprint(2, "can't exec con service: %r\n");
-	exits("can't exec");
-}
-
-void
-getstr(int fd, char *str, int len)
-{
-	char c;
-	int n;
-
-	while(--len > 0){
-		n = read(fd, &c, 1);
-		if(n < 0)
-			return;
-		if(n == 0)
-			continue;
-		*str++ = c;
-		if(c == 0)
-			break;
-	}
-	*str = '\0';
-}

+ 0 - 585
sys/src/cmd/ip/telnet.c

@@ -1,585 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include "telnet.h"
-
-int ctl = -1;		/* control fd (for break's) */
-int consctl = -1;	/* consctl fd */
-
-int ttypid;		/* pid's if the 2 processes (used to kill them) */
-int netpid;
-int interrupted;
-int localecho;
-int notkbd;
-
-static char *srv;
-
-typedef struct Comm Comm;
-struct Comm {
-	int returns;
-	int stopped;
-};
-Comm *comm;
-
-int	dodial(char*);
-void	fromkbd(int);
-void	fromnet(int);
-int	menu(Biobuf*,  int);
-void	notifyf(void*, char*);
-void	rawoff(void);
-void	rawon(void);
-void	telnet(int);
-char*	system(int, char*);
-int	echochange(Biobuf*, int);
-int	termsub(Biobuf*, uint8_t*, int);
-int	xlocsub(Biobuf*, uint8_t*, int);
-void*	share(uint32_t);
-
-static int islikeatty(int);
-
-void
-usage(void)
-{
-	fatal("usage: telnet [-Cdnr] [-s srv] net!host[!service]", 0, 0);
-}
-
-void
-main(int argc, char *argv[])
-{
-	int returns;
-
-	returns = 1;
-	ARGBEGIN{
-	case 'C':
-		opt[Echo].noway = 1;
-		break;
-	case 'd':
-		debug = 1;
-		break;
-	case 'n':
-		notkbd = 1;
-		break;
-	case 'r':
-		returns = 0;
-		break;
-	case 's':
-		srv = EARGF(usage());
-		break;
-	default:
-		usage();
-	}ARGEND
-
-	if(argc != 1)
-		usage();
-
-	/* options we need routines for */
-	opt[Echo].change = echochange;
-	opt[Term].sub = termsub;
-	opt[Xloc].sub = xlocsub;
-
-	comm = share(sizeof(comm));
-	comm->returns = returns;
-
-	telnet(dodial(argv[0]));
-}
-
-/*
- *  dial and return a data connection
- */
-int
-dodial(char *dest)
-{
-	char *name;
-	int data;
-	char devdir[NETPATHLEN];
-
-	name = netmkaddr(dest, "tcp", "telnet");
-	data = dial(name, 0, devdir, 0);
-	if(data < 0)
-		fatal("%s: %r", name, 0);
-	fprint(2, "connected to %s on %s\n", name, devdir);
-	return data;
-}
-
-void
-post(char *srv, int fd)
-{
-	int f;
-	char buf[32];
-
-	f = create(srv, OWRITE, 0666);
-	if(f < 0)
-		sysfatal("create %s: %r", srv);
-	snprint(buf, sizeof buf, "%d", fd);
-	if(write(f, buf, strlen(buf)) != strlen(buf))
-		sysfatal("write %s: %r", srv);
-	close(f);
-}
-
-/*
- *  two processes pass bytes back and forth between the
- *  terminal and the network.
- */
-void
-telnet(int net)
-{
-	int pid;
-	int p[2];
-	char *svc;
-
-	rawoff();
-	svc = nil;
-	if (srv) {
-		if(pipe(p) < 0)
-			sysfatal("pipe: %r");
-		if (srv[0] != '/')
-			svc = smprint("/srv/%s", srv);
-		else
-			svc = srv;
-		post(svc, p[0]);
-		close(p[0]);
-		dup(p[1], 0);
-		dup(p[1], 1);
-		/* pipe is now std in & out */
-	}
-	ttypid = getpid();
-	switch(pid = rfork(RFPROC|RFFDG|RFMEM)){
-	case -1:
-		perror("con");
-		exits("fork");
-	case 0:
-		rawoff();
-		notify(notifyf);
-		fromnet(net);
-		if (svc)
-			remove(svc);
-		sendnote(ttypid, "die");
-		exits(0);
-	default:
-		netpid = pid;
-		notify(notifyf);
-		fromkbd(net);
-		if(notkbd)
-			for(;;)
-				sleep(1000); // sleep(0) is a cpuhog
-		if (svc)
-			remove(svc);
-		sendnote(netpid, "die");
-		exits(0);
-	}
-}
-
-/*
- *  Read the keyboard and write it to the network.  '^\' gets us into
- *  the menu.
- */
-void
-fromkbd(int net)
-{
-	Biobuf ib, ob;
-	int c, likeatty;
-	int eofs;
-
-	Binit(&ib, 0, OREAD);
-	Binit(&ob, net, OWRITE);
-
-	likeatty = islikeatty(0);
-	eofs = 0;
-	for(;;){
-		c = Bgetc(&ib);
-
-		/*
-		 *  with raw off, all ^D's get turned into Eof's.
-		 *  change them back.
-		 *  10 in a row implies that the terminal is really gone so
-		 *  just hang up.
-		 */
-		if(c < 0){
-			if(notkbd)
-				return;
-			if(eofs++ > 10)
-				return;
-			c = 004;
-		} else
-			eofs = 0;
-
-		/*
-		 *  if not in binary mode, look for the ^\ escape to menu.
-		 *  also turn \n into \r\n
-		 */
-		if(likeatty || !opt[Binary].local){
-			if(c == 0034){ /* CTRL \ */
-				if(Bflush(&ob) < 0)
-					return;
-				if(menu(&ib, net) < 0)
-					return;
-				continue;
-			}
-		}
-		if(!opt[Binary].local){
-			if(c == '\n'){
-				/*
-				 *  This is a very strange use of the SGA option.
-				 *  I did this because some systems that don't
-				 *  announce a willingness to supress-go-ahead
-				 *  need the \r\n sequence to recognize input.
-				 *  If someone can explain this to me, please
-				 *  send me mail. - presotto
-				 */
-				if(opt[SGA].remote){
-					c = '\r';
-				} else {
-					if(Bputc(&ob, '\r') < 0)
-						return;
-				}
-			}
-		}
-		if(Bputc(&ob, c) < 0)
-			return;
-		if(Bbuffered(&ib) == 0)
-			if(Bflush(&ob) < 0)
-				return;
-	}
-}
-
-/*
- *  Read from the network and write to the screen.  If 'stopped' is set
- *  spin and don't read.  Filter out spurious carriage returns.
- */
-void
-fromnet(int net)
-{
-	int c;
-	int crnls = 0, freenl = 0, eofs;
-	Biobuf ib, ob;
-
-	Binit(&ib, net, OREAD);
-	Binit(&ob, 1, OWRITE);
-	eofs = 0;
-	for(;;){
-		if(Bbuffered(&ib) == 0)
-			Bflush(&ob);
-		if(interrupted){
-			interrupted = 0;
-			send2(net, Iac, Interrupt);
-		}
-		c = Bgetc(&ib);
-		if(c < 0){
-			if(eofs++ >= 2)
-				return;
-			continue;
-		}
-		eofs = 0;
-		switch(c){
-		case '\n':	/* skip nl after string of cr's */
-			if(!opt[Binary].local && !comm->returns){
-				++crnls;
-				if(freenl == 0)
-					break;
-				freenl = 0;
-				continue;
-			}
-			break;
-		case '\r':	/* first cr becomes nl, remainder dropped */
-			if(!opt[Binary].local && !comm->returns){
-				if(crnls++ == 0){
-					freenl = 1;
-					c = '\n';
-					break;
-				}
-				continue;
-			}
-			break;
-		case 0:		/* remove nulls from crnl string */
-			if(crnls)
-				continue;
-			break;
-
-		case Iac:
-			crnls = 0;
-			freenl = 0;
-			c = Bgetc(&ib);
-			if(c == Iac)
-				break;
-			if(Bflush(&ob) < 0)
-				return;
-			if(control(&ib, c) < 0)
-				return;
-			continue;
-
-		default:
-			crnls = 0;
-			freenl = 0;
-			break;
-		}
-		if(Bputc(&ob, c) < 0)
-			return;
-	}
-}
-
-/*
- *  turn keyboard raw mode on
- */
-void
-rawon(void)
-{
-	if(debug)
-		fprint(2, "rawon\n");
-	if(consctl < 0)
-		consctl = open("/dev/consctl", OWRITE);
-	if(consctl < 0){
-		fprint(2, "%s: can't open consctl: %r\n", argv0);
-		return;
-	}
-	write(consctl, "rawon", 5);
-}
-
-/*
- *  turn keyboard raw mode off
- */
-void
-rawoff(void)
-{
-	if(debug)
-		fprint(2, "rawoff\n");
-	if(consctl < 0)
-		consctl = open("/dev/consctl", OWRITE);
-	if(consctl < 0){
-		fprint(2, "%s: can't open consctl: %r\n", argv0);
-		return;
-	}
-	write(consctl, "rawoff", 6);
-}
-
-/*
- *  control menu
- */
-#define STDHELP	"\t(b)reak, (i)nterrupt, (q)uit, (r)eturns, (!cmd), (.)continue\n"
-
-int
-menu(Biobuf *bp, int net)
-{
-	char *cp;
-	int done;
-
-	comm->stopped = 1;
-
-	rawoff();
-	fprint(2, ">>> ");
-	for(done = 0; !done; ){
-		cp = Brdline(bp, '\n');
-		if(cp == 0){
-			comm->stopped = 0;
-			return -1;
-		}
-		cp[Blinelen(bp)-1] = 0;
-		switch(*cp){
-		case '!':
-			system(Bfildes(bp), cp+1);
-			done = 1;
-			break;
-		case '.':
-			done = 1;
-			break;
-		case 'q':
-			comm->stopped = 0;
-			return -1;
-		case 'o':
-			switch(*(cp+1)){
-			case 'd':
-				send3(net, Iac, Do, atoi(cp+2));
-				break;
-			case 'w':
-				send3(net, Iac, Will, atoi(cp+2));
-				break;
-			}
-			break;
-		case 'r':
-			comm->returns = !comm->returns;
-			done = 1;
-			break;
-		case 'i':
-			send2(net, Iac, Interrupt);
-			break;
-		case 'b':
-			send2(net, Iac, Break);
-			break;
-		default:
-			fprint(2, STDHELP);
-			break;
-		}
-		if(!done)
-			fprint(2, ">>> ");
-	}
-
-	rawon();
-	comm->stopped = 0;
-	return 0;
-}
-
-/*
- *  ignore interrupts
- */
-void
-notifyf(void *a, char *msg)
-{
-	USED(a);
-	if(strcmp(msg, "interrupt") == 0){
-		interrupted = 1;
-		noted(NCONT);
-	}
-	if(strcmp(msg, "hangup") == 0)
-		noted(NCONT);
-	noted(NDFLT);
-}
-
-/*
- *  run a command with the network connection as standard IO
- */
-char *
-system(int fd, char *cmd)
-{
-	int pid;
-	int p;
-	static Waitmsg msg;
-
-	if((pid = fork()) == -1){
-		perror("con");
-		return "fork failed";
-	}
-	else if(pid == 0){
-		dup(fd, 0);
-		close(ctl);
-		close(fd);
-		if(*cmd)
-			execl("/bin/rc", "rc", "-c", cmd, nil);
-		else
-			execl("/bin/rc", "rc", nil);
-		perror("con");
-		exits("exec");
-	}
-	for(p = waitpid(); p >= 0; p = waitpid()){
-		if(p == pid)
-			return msg.msg;
-	}
-	return "lost child";
-}
-
-/*
- *  suppress local echo if the remote side is doing it
- */
-int
-echochange(Biobuf *bp, int cmd)
-{
-	USED(bp);
-
-	switch(cmd){
-	case Will:
-		rawon();
-		break;
-	case Wont:
-		rawoff();
-		break;
-	}
-	return 0;
-}
-
-/*
- *  send terminal type to the other side
- */
-int
-termsub(Biobuf *bp, uint8_t *sub, int n)
-{
-	unsigned char buf[64];
-	char *term;
-	unsigned char *p = buf;
-
-	if(n < 1)
-		return 0;
-	if(sub[0] == 1){
-		*p++ = Iac;
-		*p++ = Sb;
-		*p++ = opt[Term].code;
-		*p++ = 0;
-		term = getenv("TERM");
-		if(term == 0 || *term == 0)
-			term = "p9win";
-		strncpy((char *)p, term, sizeof(buf) - (p - buf) - 2);
-		buf[sizeof(buf)-2] = 0;
-		p += strlen((char *)p);
-		*p++ = Iac;
-		*p++ = Se;
-		return iwrite(Bfildes(bp), buf, p-buf);
-	}
-	return 0;
-}
-
-/*
- *  send an x display location to the other side
- */
-int
-xlocsub(Biobuf *bp, uint8_t *sub, int n)
-{
-	unsigned char buf[64];
-	char *term;
-	unsigned char *p = buf;
-
-	if(n < 1)
-		return 0;
-	if(sub[0] == 1){
-		*p++ = Iac;
-		*p++ = Sb;
-		*p++ = opt[Xloc].code;
-		*p++ = 0;
-		term = getenv("XDISP");
-		if(term == 0 || *term == 0)
-			term = "unknown";
-		strncpy((char *)p, term, p - buf - 2);
-		p += strlen(term);
-		*p++ = Iac;
-		*p++ = Se;
-		return iwrite(Bfildes(bp), buf, p-buf);
-	}
-	return 0;
-}
-
-static int
-islikeatty(int fd)
-{
-	char buf[64];
-
-	if(fd2path(fd, buf, sizeof buf) != 0)
-		return 0;
-
-	/* might be /mnt/term/dev/cons */
-	return strlen(buf) >= 9 && strcmp(buf+strlen(buf)-9, "/dev/cons") == 0;
-}
-
-/*
- *  create a shared segment.  Make is start 2 meg higher than the current
- *  end of process memory.
- */
-void*
-share(uint32_t len)
-{
-	uint8_t *vastart;
-
-	vastart = sbrk(0);
-	if(vastart == (void*)-1)
-		return 0;
-	vastart += 2*1024*1024;
-
-	if(segattach(0, "shared", vastart, len) == (void*)-1)
-		return 0;
-
-	return vastart;
-}

+ 0 - 396
sys/src/cmd/ip/telnet.h

@@ -1,396 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-typedef struct Opt	Opt;
-
-int debug;
-#define DPRINT if(debug)fprint
-
-enum
-{
-	/* control characters */
-	Se=		240,		/* end subnegotiation */
-	NOP=		241,
-	Mark=		242,		/* data mark */
-	Break=		243,
-	Interrupt=	244,
-	Abort=		245,		/* TENEX ^O */
-	AreYouThere=	246,
-	Erasechar=	247,		/* erase last character */
-	Eraseline=	248,		/* erase line */
-	GoAhead=	249,		/* half duplex clear to send */
-	Sb=		250,		/* start subnegotiation */
-	Will=		251,
-	Wont=		252,
-	Do=		253,
-	Dont=		254,
-	Iac=		255,
-
-	/* options */
-	Binary=		0,
-	Echo,
-	SGA,
-	Stat,
-	Timing,
-	Det,
-	Term,
-	EOR,
-	Uid,
-	Outmark,
-	Ttyloc,
-	M3270,
-	Padx3,
-	Window,
-	Speed,
-	Flow,
-	Line,
-	Xloc,
-	Extend,
-};
-
-struct Opt
-{
-	char	*name;
-	int	code;
-	char	noway;
-	int	(*change)(Biobuf*, int);	/* routine for status change */
-	int	(*sub)(Biobuf*, uint8_t*, int n);	/* routine for subnegotiation */
-	char	remote;				/* remote value */
-	char	local;				/* local value */
-};
-
-Opt opt[] =
-{
-	[Binary]	= { "binary",			0,  0, },
-	[Echo]		= { "echo",			1,  0, },
-	[SGA]		= { "suppress Go Ahead",	3,  0, },
-	[Stat]		= { "status",			5,  1, },
-	[Timing]	= { "timing",			6,  1, },
-	[Det]		= { "det",			20, 1, },
-	[Term]		= { "terminal",			24, 0, },
-	[EOR]		= { "end of record",		25, 1, },
-	[Uid]		= { "uid",			26, 1, },
-	[Outmark]	= { "outmark",			27, 1, },
-	[Ttyloc]	= { "ttyloc",			28, 1, },
-	[M3270]		= { "3270 mode",		29, 1, },
-	[Padx3]		= { "pad x.3",			30, 1, },
-	[Window]	= { "window size",		31, 1, },
-	[Speed]		= { "speed",			32, 1, },
-	[Flow]		= { "flow control",		33, 1, },
-	[Line]		= { "line mode",		34, 1, },
-	[Xloc]		= { "X display loc",		35, 0, },
-	[Extend]	= { "Extended",			255, 1, },
-};
-
-int	control(Biobuf*, int);
-Opt*	findopt(int);
-int	will(Biobuf*);
-int	wont(Biobuf*);
-int	doit(Biobuf*);
-int	dont(Biobuf*);
-int	sub(Biobuf*);
-int	send2(int, int, int);
-int	send3(int, int, int, int);
-int	sendnote(int, char*);
-void	fatal(char*, void*, void*);
-char*	syserr(void);
-int	wasintr(void);
-long	iread(int, void*, int);
-long	iwrite(int, void*, int);
-void	binit(Biobuf*, int);
-void	berase(Biobuf*);
-void	bkill(Biobuf*);
-
-/*
- *  parse telnet control messages
- */
-int
-control(Biobuf *bp, int c)
-{
-	if(c < 0)
-		return -1;
-	switch(c){
-	case AreYouThere:
-		fprint(Bfildes(bp), "Plan 9 telnet, version 1\r\n");
-		break;
-	case Sb:
-		return sub(bp);
-	case Will:
-		return will(bp);
-	case Wont:
-		return wont(bp);
-	case Do:
-		return doit(bp);
-	case Dont:
-		return dont(bp);
-	case Se:
-		fprint(2, "telnet: SE without an SB\n");
-		break;
-	default:
-		break;
-	}
-	return 0;
-}
-
-Opt*
-findopt(int c)
-{
-	Opt *o;
-
-	for(o = opt; o <= &opt[Extend]; o++)
-		if(o->code == c)
-			return o;
-	return 0;
-}
-
-int
-will(Biobuf *bp)
-{
-	Opt *o;
-	int c;
-	int rv = 0;
-
-	c = Bgetc(bp);
-	if(c < 0)
-		return -1;
-	DPRINT(2, "will %d\n", c);
-	o = findopt(c);
-	if(o == 0){
-		send3(Bfildes(bp), Iac, Dont, c);
-		return 0;
-	}
-	if(o->noway)
-		send3(Bfildes(bp), Iac, Dont, c);
-	else if(o->remote == 0)
-		rv |= send3(Bfildes(bp), Iac, Do, c);
-	if(o->remote == 0){
-		if(o->change)
-			rv |= (*o->change)(bp, Will);
-	}
-	o->remote = 1;
-	return rv;
-}
-
-int
-wont(Biobuf *bp)
-{
-	Opt *o;
-	int c;
-	int rv = 0;
-
-	c = Bgetc(bp);
-	if(c < 0)
-		return -1;
-	DPRINT(2, "wont %d\n", c);
-	o = findopt(c);
-	if(o == 0)
-		return 0;
-	if(o->remote){
-		if(o->change)
-			rv |= (*o->change)(bp, Wont);
-		rv |= send3(Bfildes(bp), Iac, Dont, c);
-	}
-	o->remote = 0;
-	return rv;
-}
-
-int
-doit(Biobuf *bp)
-{
-	Opt *o;
-	int c;
-	int rv = 0;
-
-	c = Bgetc(bp);
-	if(c < 0)
-		return -1;
-	DPRINT(2, "do %d\n", c);
-	o = findopt(c);
-	if(o == 0 || o->noway){
-		send3(Bfildes(bp), Iac, Wont, c);
-		return 0;
-	}
-	if(o->noway)
-		return 0;
-	if(o->local == 0){
-		if(o->change)
-			rv |= (*o->change)(bp, Do);
-		rv |= send3(Bfildes(bp), Iac, Will, c);
-	}
-	o->local = 1;
-	return rv;
-}
-
-int
-dont(Biobuf *bp)
-{
-	Opt *o;
-	int c;
-	int rv = 0;
-
-	c = Bgetc(bp);
-	if(c < 0)
-		return -1;
-	DPRINT(2, "dont %d\n", c);
-	o = findopt(c);
-	if(o == 0)
-		return 0;
-	if(o->noway)
-		return 0;
-	if(o->local){
-		o->local = 0;
-		if(o->change)
-			rv |= (*o->change)(bp, Dont);
-		rv |= send3(Bfildes(bp), Iac, Wont, c);
-	}
-	o->local = 0;
-	return rv;
-}
-
-/* read in a subnegotiation message and pass it to a routine for that option */
-int
-sub(Biobuf *bp)
-{
-	uint8_t subneg[128];
-	uint8_t *p;
-	Opt *o;
-	int c;
-
-	p = subneg;
-	for(;;){
-		c = Bgetc(bp);
-		if(c == Iac){
-			c = Bgetc(bp);
-			if(c == Se)
-				break;
-			if(p < &subneg[sizeof(subneg)])
-				*p++ = Iac;
-		}
-		if(c < 0)
-			return -1;
-		if(p < &subneg[sizeof(subneg)])
-			*p++ = c;
-	}
-	if(p == subneg)
-		return 0;
-	DPRINT(2, "sub %d %d n = %d\n", subneg[0], subneg[1], (int)(p - subneg - 1));
-	o = findopt(subneg[0]);
-	if(o == 0 || o->sub == 0)
-		return 0;
-	return (*o->sub)(bp, subneg+1, p - subneg - 1);
-}
-
-void
-sendd(int c0, int c1)
-{
-	char *t = 0;
-
-	switch(c0){
-	case Will:
-		t = "Will";
-		break;
-	case Wont:
-		t = "Wont";
-		break;
-	case Do:
-		t = "Do";
-		break;
-	case Dont:
-		t = "Dont";
-		break;
-	}
-	if(t)
-		DPRINT(2, "r %s %d\n", t, c1);
-}
-
-int
-send2(int f, int c0, int c1)
-{
-	uint8_t buf[2];
-
-	buf[0] = c0;
-	buf[1] = c1;
-	return iwrite(f, buf, 2) == 2 ? 0 : -1;
-}
-
-int
-send3(int f, int c0, int c1, int c2)
-{
-	uint8_t buf[3];
-
-	buf[0] = c0;
-	buf[1] = c1;
-	buf[2] = c2;
-	sendd(c1, c2);
-	return iwrite(f, buf, 3) == 3 ? 0 : -1;
-}
-
-int
-sendnote(int pid, char *msg)
-{
-	int fd;
-	char name[128];
-
-	sprint(name, "/proc/%d/note", pid);
-	fd = open(name, OWRITE);
-	if(fd < 0)
-		return -1;
-	if(write(fd, msg, strlen(msg))!=strlen(msg))
-		return -1;
-	return close(fd);
-}
-
-void
-fatal(char *fmt, void *a0, void *a1)
-{
-	char buf[128];
-
-	sprint(buf, fmt, a0, a1);
-	fprint(2, "%s: %s\n", argv0, buf);
-	exits(buf);
-}
-
-char*
-syserr(void)
-{
-	static char err[ERRMAX];
-
-	errstr(err, sizeof err);
-	return err;
-}
-
-int
-wasintr(void)
-{
-	return strcmp(syserr(), "interrupted") == 0;
-}
-
-long
-iread(int f, void *a, int n)
-{
-	long m;
-
-	for(;;){
-		m = read(f, a, n);
-		if(m >= 0 || !wasintr())
-			break;
-	}
-	return m;
-}
-
-long
-iwrite(int f, void *a, int n)
-{
-	long m;
-
-	m = write(f, a, n);
-	if(m < 0 && wasintr())
-		return n;
-	return m;
-}

+ 0 - 657
sys/src/cmd/ip/telnetd.c

@@ -1,657 +0,0 @@
-/*
- * This file is part of the UCB release of Plan 9. It is subject to the license
- * terms in the LICENSE file found in the top-level directory of this
- * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
- * part of the UCB release of Plan 9, including this file, may be copied,
- * modified, propagated, or distributed except according to the terms contained
- * in the LICENSE file.
- */
-
-#include <u.h>
-#include <libc.h>
-#include <bio.h>
-#include <auth.h>
-#include <mp.h>
-#include <libsec.h>
-
-#include "../ip/telnet.h"
-
-/*  console state (for consctl) */
-typedef struct Consstate	Consstate;
-struct Consstate{
-	int raw;
-	int hold;
-};
-Consstate *cons;
-
-int notefd;		/* for sending notes to the child */
-int noproto;		/* true if we shouldn't be using the telnet protocol */
-int trusted;		/* true if we need not authenticate - current user
-				is ok */
-int nonone = 1;		/* don't allow none logins */
-int noworldonly;	/* only noworld accounts */
-
-enum
-{
-	Maxpath=	256,
-	Maxuser=	64,
-	Maxvar=		32,
-};
-
-/* input and output buffers for network connection */
-Biobuf	netib;
-Biobuf	childib;
-char	remotesys[Maxpath];	/* name of remote system */
-
-int	alnum(int);
-int	conssim(void);
-int	fromchild(char*, int);
-int	fromnet(char*, int);
-int	termchange(Biobuf*, int);
-int	termsub(Biobuf*, uint8_t*, int);
-int	xlocchange(Biobuf*, int);
-int	xlocsub(Biobuf*, uint8_t*, int);
-int	challuser(char*);
-int	noworldlogin(char*);
-void*	share(uint32_t);
-int	doauth(char*);
-
-#define TELNETLOG "telnet"
-
-void
-logit(char *fmt, ...)
-{
-	va_list arg;
-	char buf[8192];
-
-	va_start(arg, fmt);
-	vseprint(buf, buf + sizeof(buf) / sizeof(*buf), fmt, arg);
-	va_end(arg);
-	syslog(0, TELNETLOG, "(%s) %s", remotesys, buf);
-}
-
-void
-getremote(char *dir)
-{
-	int fd, n;
-	char remfile[Maxpath];
-
-	sprint(remfile, "%s/remote", dir);
-	fd = open(remfile, OREAD);
-	if(fd < 0)
-		strcpy(remotesys, "unknown2");
-	n = read(fd, remotesys, sizeof(remotesys)-1);
-	if(n>0)
-		remotesys[n-1] = 0;
-	else
-		strcpy(remotesys, remfile);
-	close(fd);
-}
-
-void
-main(int argc, char *argv[])
-{
-	char buf[1024];
-	int fd;
-	char user[Maxuser];
-	int tries = 0;
-	int childpid;
-	int n, eofs;
-
-	memset(user, 0, sizeof(user));
-	ARGBEGIN {
-	case 'n':
-		opt[Echo].local = 1;
-		noproto = 1;
-		break;
-	case 'p':
-		noproto = 1;
-		break;
-	case 'a':
-		nonone = 0;
-		break;
-	case 't':
-		trusted = 1;
-		strncpy(user, getuser(), sizeof(user)-1);
-		break;
-	case 'u':
-		strncpy(user, ARGF(), sizeof(user)-1);
-		break;
-	case 'd':
-		debug = 1;
-		break;
-	case 'N':
-		noworldonly = 1;
-		break;
-	} ARGEND
-
-	if(argc)
-		getremote(argv[argc-1]);
-	else
-		strcpy(remotesys, "unknown");
-
-	/* options we need routines for */
-	opt[Term].change = termchange;
-	opt[Term].sub = termsub;
-	opt[Xloc].sub = xlocsub;
-
-	/* setup default telnet options */
-	if(!noproto){
-		send3(1, Iac, Will, opt[Echo].code);
-		send3(1, Iac, Do, opt[Term].code);
-		send3(1, Iac, Do, opt[Xloc].code);
-	}
-
-	/* shared data for console state */
-	cons = share(sizeof(Consstate));
-	if(cons == 0)
-		fatal("shared memory", 0, 0);
-
-	/* authenticate and create new name space */
-	Binit(&netib, 0, OREAD);
-	if (!trusted){
-		while(doauth(user) < 0)
-			if(++tries == 5){
-				logit("failed as %s: %r", user);
-				print("authentication failure:%r\r\n");
-				exits("authentication");
-			}
-	}
-	logit("logged in as %s", user);
-	putenv("service", "con");
-
-	/* simulate /dev/consctl and /dev/cons using pipes */
-	fd = conssim();
-	if(fd < 0)
-		fatal("simulating", 0, 0);
-	Binit(&childib, fd, OREAD);
-
-	/* start a shell in a different process group */
-	switch(childpid = rfork(RFPROC|RFNAMEG|RFFDG|RFNOTEG)){
-	case -1:
-		fatal("fork", 0, 0);
-	case 0:
-		close(fd);
-		fd = open("/dev/cons", OREAD);
-		dup(fd, 0);
-		close(fd);
-		fd = open("/dev/cons", OWRITE);
-		dup(fd, 1);
-		dup(fd, 2);
-		close(fd);
-		segdetach(cons);
-		execl("/bin/rc", "rc", "-il", nil);
-		fatal("/bin/rc", 0, 0);
-	default:
-		sprint(buf, "/proc/%d/notepg", childpid);
-		notefd = open(buf, OWRITE);
-		break;
-	}
-
-	/* two processes to shuttle bytes twixt children and network */
-	switch(fork()){
-	case -1:
-		fatal("fork", 0, 0);
-	case 0:
-		eofs = 0;
-		for(;;){
-			n = fromchild(buf, sizeof(buf));
-			if(n <= 0){
-				if(eofs++ > 2)
-					break;
-				continue;
-			}
-			eofs = 0;
-			if(write(1, buf, n) != n)
-				break;
-		}
-		break;
-	default:
-		while((n = fromnet(buf, sizeof(buf))) >= 0)
-			if(write(fd, buf, n) != n)
-				break;
-		break;
-	}
-
-	/* kill off all server processes */
-	sprint(buf, "/proc/%d/notepg", getpid());
-	fd = open(buf, OWRITE);
-	write(fd, "die", 3);
-	exits(0);
-}
-
-void
-prompt(char *p, char *b, int n, int raw)
-{
-	char *e;
-	int i;
-	int echo;
-
-	echo = opt[Echo].local;
-	if(raw)
-		opt[Echo].local = 0;
-	print("%s: ", p);
-	for(e = b+n; b < e;){
-		i = fromnet(b, e-b);
-		if(i <= 0)
-			exits("fromnet: hungup");
-		b += i;
-		if(*(b-1) == '\n' || *(b-1) == '\r'){
-			*(b-1) = 0;
-			break;
-		}
-	}
-	if(raw)
-		opt[Echo].local = echo;
-}
-
-/*
- *  challenge user
- */
-int
-challuser(char *user)
-{
-	char nchall[64];
-	char response[64];
-	Chalstate *ch;
-	AuthInfo *ai;
-
-	if(strcmp(user, "none") == 0){
-		if(nonone)
-			return -1;
-		newns("none", nil);
-		return 0;
-	}
-	if((ch = auth_challenge("proto=p9cr role=server user=%q", user)) == nil)
-		return -1;
-	snprint(nchall, sizeof nchall, "challenge: %s\r\nresponse", ch->chal);
-	prompt(nchall, response, sizeof response, 0);
-	ch->resp = response;
-	ch->nresp = strlen(response);
-	ai = auth_response(ch);
-	auth_freechal(ch);
-	if(ai == nil){
-		rerrstr(response, sizeof response);
-		print("!%s\n", response);
-		return -1;
-	}
-	if(auth_chuid(ai, nil) < 0)
-		return -1;
-	return 0;
-}
-/*
- *  use the in the clear apop password to change user id
- */
-int
-noworldlogin(char *user)
-{
-	char password[256];
-
-	prompt("password", password, sizeof(password), 1);
-	if(login(user, password, "/lib/namespace.noworld") < 0)
-		return -1;
-	rfork(RFNOMNT);	/* sandbox */
-	return 0;
-}
-
-int
-doauth(char *user)
-{
-	if(*user == 0)
-		prompt("user", user, Maxuser, 0);
-	if(noworld(user))
-		return noworldlogin(user);
-	if(noworldonly)
-		return -1;
-	return challuser(user);
-
-}
-
-/*
- *  Process some input from the child, add protocol if needed.  If
- *  the input buffer goes empty, return.
- */
-int
-fromchild(char *bp, int len)
-{
-	int c;
-	char *start;
-
-	for(start = bp; bp-start < len-1; ){
-		c = Bgetc(&childib);
-		if(c < 0){
-			if(bp == start)
-				return -1;
-			else
-				break;
-		}
-		if(cons->raw == 0 && c == '\n')
-			*bp++ = '\r';
-		*bp++ = c;
-		if(Bbuffered(&childib) == 0)
-			break;
-	}
-	return bp-start;
-}
-
-/*
- *  Read from the network up to a '\n' or some other break.
- *
- *  If in binary mode, buffer characters but don't
- *
- *  The following characters are special:
- *	'\r\n's and '\r's get turned into '\n's.
- *	^H erases the last character buffered.
- *	^U kills the whole line buffered.
- *	^W erases the last word
- *	^D causes a 0-length line to be returned.
- *	Intr causes an "interrupt" note to be sent to the children.
- */
-#define ECHO(c) { *ebp++ = (c); }
-int
-fromnet(char *bp, int len)
-{
-	int c;
-	char echobuf[1024];
-	char *ebp;
-	char *start;
-	static int crnl;
-	static int doeof;
-
-
-	/* simulate an EOF as a 0 length input */
-	if(doeof){
-		doeof = 0;
-		return 0;
-	}
-
-	for(ebp = echobuf,start = bp; bp-start < len && ebp-echobuf < sizeof(echobuf); ){
-		c = Bgetc(&netib);
-		if(c < 0){
-			if(bp == start)
-				return -1;
-			else
-				break;
-		}
-
-		/* telnet protocol only */
-		if(!noproto){
-			/* protocol messages */
-			switch(c){
-			case Iac:
-				crnl = 0;
-				c = Bgetc(&netib);
-				if(c == Iac)
-					break;
-				control(&netib, c);
-				continue;
-			}
-
-		}
-
-		/* \r\n or \n\r become \n  */
-		if(c == '\r' || c == '\n'){
-			if(crnl && crnl != c){
-				crnl = 0;
-				continue;
-			}
-			if(cons->raw == 0 && opt[Echo].local){
-				ECHO('\r');
-				ECHO('\n');
-			}
-			crnl = c;
-			if(cons->raw == 0)
-				*bp++ = '\n';
-			else
-				*bp++ = c;
-			break;
-		} else
-			crnl = 0;
-
-		/* raw processing (each character terminates */
-		if(cons->raw){
-			*bp++ = c;
-			break;
-		}
-
-		/* in binary mode, there are no control characters */
-		if(opt[Binary].local){
-			if(opt[Echo].local)
-				ECHO(c);
-			*bp++ = c;
-			continue;
-		}
-
-		/* cooked processing */
-		switch(c){
-		case 0x00:
-			if(noproto)		/* telnet ignores nulls */
-				*bp++ = c;
-			continue;
-		case 0x04:
-			if(bp != start)
-				doeof = 1;
-			goto out;
-
-		case 0x08:	/* ^H */
-			if(start < bp)
-				bp--;
-			if(opt[Echo].local)
-				ECHO(c);
-			break;
-
-		case 0x15:	/* ^U */
-			bp = start;
-			if(opt[Echo].local){
-				ECHO('^');
-				ECHO('U');
-				ECHO('\r');
-				ECHO('\n');
-			}
-			break;
-
-		case 0x17:	/* ^W */
-			if (opt[Echo].local) {
-				while (--bp >= start && !alnum(*bp))
-					ECHO('\b');
-				while (bp >= start && alnum(*bp)) {
-					ECHO('\b');
-					bp--;
-				}
-				bp++;
-			}
-			break;
-
-		case 0x7f:	/* Del */
-			write(notefd, "interrupt", 9);
-			bp = start;
-			break;
-
-		default:
-			if(opt[Echo].local)
-				ECHO(c);
-			*bp++ = c;
-		}
-		if(ebp != echobuf)
-			write(1, echobuf, ebp-echobuf);
-		ebp = echobuf;
-	}
-out:
-	if(ebp != echobuf)
-		write(1, echobuf, ebp-echobuf);
-	return bp - start;
-}
-
-int
-termchange(Biobuf *bp, int cmd)
-{
-	unsigned char buf[8];
-	unsigned char *p = buf;
-
-	if(cmd != Will)
-		return 0;
-
-	/* ask other side to send term type info */
-	*p++ = Iac;
-	*p++ = Sb;
-	*p++ = opt[Term].code;
-	*p++ = 1;
-	*p++ = Iac;
-	*p++ = Se;
-	return iwrite(Bfildes(bp), buf, p-buf);
-}
-
-int
-termsub(Biobuf *bp, uint8_t *sub, int n)
-{
-	char term[Maxvar];
-
-	USED(bp);
-	if(n-- < 1 || sub[0] != 0)
-		return 0;
-	if(n >= sizeof term)
-		n = sizeof term;
-	strncpy(term, (char*)sub, n);
-	putenv("TERM", term);
-	return 0;
-}
-
-int
-xlocchange(Biobuf *bp, int cmd)
-{
-	unsigned char buf[8];
-	unsigned char *p = buf;
-
-	if(cmd != Will)
-		return 0;
-
-	/* ask other side to send x display info */
-	*p++ = Iac;
-	*p++ = Sb;
-	*p++ = opt[Xloc].code;
-	*p++ = 1;
-	*p++ = Iac;
-	*p++ = Se;
-	return iwrite(Bfildes(bp), buf, p-buf);
-}
-
-int
-xlocsub(Biobuf *bp, uint8_t *sub, int n)
-{
-	char xloc[Maxvar];
-
-	USED(bp);
-	if(n-- < 1 || sub[0] != 0)
-		return 0;
-	if(n >= sizeof xloc)
-		n = sizeof xloc;
-	strncpy(xloc, (char*)sub, n);
-	putenv("DISPLAY", xloc);
-	return 0;
-}
-
-/*
- *  create a shared segment.  Make is start 2 meg higher than the current
- *  end of process memory.
- */
-void*
-share(uint32_t len)
-{
-	uint8_t *vastart;
-
-	vastart = sbrk(0);
-	if(vastart == (void*)-1)
-		return 0;
-	vastart += 2*1024*1024;
-
-	if(segattach(0, "shared", vastart, len) == (void*)-1)
-		return 0;
-
-	return vastart;
-}
-
-/*
- *  bind a pipe onto consctl and keep reading it to