Submitted-by: Dan Bernstein <brnstnd@kramden.acf.nyu.edu>
Archive-name: pty/part07
Archive-date: Fri Oct 19 19:51:47 GMT 1990

#! /bin/sh
# This is a shell archive.  Remove anything before this line, then unpack
# it by saving it into a file and typing "sh file".  To overwrite existing
# files, type "sh file -c".  You can also feed this as standard input via
# unshar, or by typing "sh <file", e.g..  If this archive is complete, you
# will see the following message at the end:
#		"End of shell archive."
# Contents:  INSTALL.ctrl util/lock.c.ctrl util/script.tidy.ctrl
#   util/wall.c.ctrl util/write.c.ctrl
# Wrapped by brnstnd@kramden on Fri Oct 19 15:38:48 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
echo shar: Five of the original files may have lost control characters in transit.
echo shar: This archive extracts correct versions.
if test -f 'INSTALL.ctrl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'INSTALL.ctrl'\"
else
echo shar: Extracting \"'INSTALL.ctrl'\" \(25242 characters\)
sed "s/^X//" >'INSTALL.ctrl' <<'END_OF_FILE'
X#!/bin/sh
X# This is a shell script. Feed it to sh.
Xecho '
XHi, and welcome to the pty install script.
Xpty is a program for managing pseudo-terminals.
X
XI'\''m not actually going to install anything.
XI'\''ll just guide you through what has to be done,
Xfrom compiling through installation.
X
XOne advantage of this hands-off philosophy is that
Xyou can kill and restart this script at any time.
XYou may prefer to read through INSTALLREADABLE,
Xwhich has the same information.
X
XIn the first part of this script, I'\''ll lead you through configuration.
XFor the moment, don'\''t actually change anything in your system. Just
Xalternate between reading this script and fooling around with the
XMakefile, and I'\''ll remind you later, after compilation, of what has
Xto be changed elsewhere.
X
XI need the following programs: echo, tr [-d], man, sed [-n], grep, test.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XThe first versions of pty were designed on a BSD 4.2-based system.
XDuring May 1990 pty 3.0 was written completely from scratch,
Xon a BSD 4.3-based system. It has been thoroughly tested on
Xseveral BSD 4.3-based systems, tested with a few Makefile changes
Xon several BSD 4.2-based systems, and run on at least one mutant.
X
XIf you make it through installation and testing and get pty running,
Xplease send a note to the author, Dan Bernstein, on the Internet
Xat brnstnd@nyu.edu. Let him know your computer model, OS version, and
Xwhat changes you had to make. If you have any trouble, please also get
Xin touch with the author. If you have a different kind of system with
Xpseudo-terminal support that could use a pty port, the author would
Xlove to hear about it.
X
XOne note: Like all software, pty comes without warranty, to the extent
Xpermitted by applicable law. Use it at your own risk.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XI assume that you don'\''t want to make any major changes
Xto your computer just to take advantage of pty'\''s capabilities.
XYou might not even have a privileged account, for all I know.
X
XThe first major decision you have to make is what privileges to give pty.
XObviously if you don'\''t have privileges then pty won'\''t either;
Xthis is Case UN.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XThere are several good reasons for giving programs privileges.
XMost importantly, privileged programs can precisely control access
Xto a shared resource. pty supports an interactive user list in
X/etc/utmp, a login-logout record in /usr/adm/wtmp, and controlled
Xaccess to the pseudo-terminal files themselves, including security and
Xmode changing. None of these are possible if pty isn'\''t setuid.
X
XIf your system has a lot more tty security than usual, you probably
Xwon'\''t be able to run pty without privileges. (However, if your system
Xhas a lot more tty security than usual, it'\''s almost certainly running
Xpty anyway.)
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XIf you do want pty to have privileges, you have to decide between
Xsetting up pty as root (Case ROOT) or as some other user, say ``pty'\'\''
X(Case PTY). Staying away from root has the advantage that problems
Xcan'\''t possibly destroy all security in one blow. However, root has
Xseveral advantages, mainly because of BSD limitations: 1. A process
Xcan'\''t change ownership of a file between its euid and uid. Only root
Xcan change ownership. It shouldn'\''t be necessary to change ownership
Xof ptys anyway, but that'\''s what many programs assume. 2. MAXUPRC in
X<sys/param.h> limits the number of processes under a given *effective*
Xuid. This absolutely idiotic behavior is a serious problem for programs
Xsetuid to anything other than root. pty tries to work around this
Xproblem, but there are no true solutions. 3. Despite the documentation
Xin kill(2), many machines don'\''t allow non-root processes to send
XCONT to children with a different uid. Unlike almost all other programs,
Xpty sensibly handles its child stopping and restarting; but this won'\''t
Xwork on those machines if pty isn'\''t root.
X
XYou should decide now between Case ROOT and Case PTY.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XWhether you'\''ve decided on ROOT, PTY, or UN,
Xnow is the time to check the security of the entire pty package.
XIt'\''d be difficult for anything to slip through the checks by the
Xauthor, testers, and source group moderator, but you should take
Xat least a moment to look for your pet security peeves.
X
XA couple of security notes: The only open(,O_CREAT) in pty is in
Xmaster.c, at the top of master(), of a file with a very restricted
Xform constructed from the filename of a /dev/ttyxx. There are no
Xcreat()s. The only bind() is in sock.c'\''s pty_readsock(), which is
Xcalled only from master.c'\''s master() to create a socket with a
Xsimilarly restricted name. (fnsty is changed in sigler but not in
Xmaster.) The only exec() is in slave.c, after a forced setreuid()
Xto a uid that is only set to getuid(). unlink(), mkdir(), and rename()
Xare only used with restricted pathnames.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XIn Case PTY, you have to set up a new uid, say ``pty'\'\'' (or whatever
Xusername you want). pty should not allow logins. Its password should
Xbe an asterisk; its home directory should be /nonexistent; its shell
Xshould be /bin/true. In other words, the only access to user pty
Xshould be through these setuid programs.
X
XIn any privileged case you should have group tty,
Xwhich most BSD 4.3 systems have as gid 4. 
X'
X
Xecho 'Running '\
X'$ ttygroup="`sed -n '\''s/^tty:[^:]*:\(.*\):.*/\1/p'\'' < /etc/group`" ...'
Xttygroup="`sed -n 's/^tty:[^:]*:\(.*\):.*/\1/p' < /etc/group`"
X
Xcase "$ttygroup" in
X4) echo '
XI see that you have a tty group, 4 as usual. Good.
X' ;;
X'') echo '
XYou don'\''t have a tty group. Unless you have a suitable group under a
Xdifferent name, you should add the line
Xtty:*:4:root
Xto /etc/group.
X' ;;
X*) echo '
XI see that you have a tty group, gid '"$ttygroup"' rather than 4. Okay.
X' ;;
Xesac
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XNext, we'\''re going to drudge through the config.h file.
X
XIn Cases ROOT or PTY, you have to set up a system-wide directory
Xfor storing information about pty sessions. (A session is a program
Xstuck under a pty that you can disconnect and reconnect.) Users can
Xget around this directory, storing the information in ~/.pty and
Xrevoking any privileges, with pty -xS; you can even make this default
Xby setting flagxsetuid = 0 in globals.c. However, a single system-wide
Xdirectory is safer.
X
XAnyway, that directory, PTYDIR, should be mode 0700, owner root in case
XROOT or pty in case PTY, group irrelevant. PTYDIR is defined in config.h
Xas /usr/etc/pty by default; if you choose a different directory, add
X-DPTYDIR=\"/what/ever/dir/ect/ory\" to CCOPTS in the Makefile.
X
XIn Case UN, you may want to set up a directory ~/PTY inside your home
Xdirectory, and set PTYDIR to that; you may want to set flagxsetuid = 0
Xin globals.c; or you may want to just type -xS to pty all the time. I
Xrecommend the first strategy.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XNext come pseudo-terminal pathnames. I assume that your ptys are
Xlabelled as /dev/ptyxx and /dev/ttyxx, where xx is any two-letter
Xextension. pty can support any initial strings instead of these,
Xbut some of the utilities have /dev/tty hardcoded, and lots of other
Xprograms running around assume those names. If you'\''re desperate,
Xdefine DEVMTY and DEVSTY in the Makefile, and figure out what has to
Xbe changed in util/*. (Sorry.)
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XThe extension is traditionally [p-za-o][0-9a-f]. The first letter of the
Xsecond string is special: if /dev/ttyq0 doesn'\''t exist, for example, then
Xnone of /dev/ttyq[0-9a-f] will be used. (That'\''s called a pty bank.)
X
XYou can change those strings by defining, e.g., PTY1=\"ABCDEFG\" or
XPTY2=\"02468abfq\" in the Makefile. You have at least four choices here:
X1. Give pty its own, new, banks of new pseudo-terminals with weird bank
Xnames not including a through z, and define PTY1 appropriately. pty will
Xonly use those new ptys, and older programs will just use the old ptys.
XThis may require reconfiguring your system for the larger number of
Xterminals. 2. Give pty some new banks, and take out some old ones to
Xmake up for it. 3. Give pty a chunk of the old banks. 4. Give pty all
Xthe old banks.
X
XNote that pty searches randomly through PTY1 and PTY2 by default; for
Xefficiency, PTY1 really should reflect exactly the pty banks you have.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XSo now you'\''ve decided on new ptys, or set aside some or all of your
Xold ptys, and changed PTY1 and PTY2 appropriately. Because BSD gives a
Xprocess very little control over its controlling terminal, pty has to
Xpass a terminal name explicitly when it reconnects. If any of your tty
X(not just pseudo-tty!) filenames are longer than 30 characters, you have
Xto set -DTTYNAMELEN=60 (or whatever) in the Makefile.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
X/etc/utmp has traditionally listed all users logged on.
XThis nebulous concept has evolved through the years; given the way
Xthat most programs use utmp, utmp is probably better defined as a
Xlist of all interactive sessions. Anyway, pty supports this file,
Xand will make an entry in it when given -xu. If you have a different
Xfile, add -DPTYUTMP_FILE=\"/foo/bar/utmp\" to DEFINES in the Makefile.
X
XNote that /etc/utmp is unprotected (mode 666) on Suns. This was Sun'\''s
Xattempt to let unprivileged programs manage the file. Unforunately, this
Xerror in judgment opens up a huge security hole, which even on
Xsingle-user machines is an invitation to make mistakes. I advise you to
Xmake /etc/utmp owned by root in Case ROOT or pty in Case PTY, mode 644.
XThere aren'\''t many unprivileged programs that don'\''t understand the
Xpty interface; people on non-Suns have survived so far, and there'\''s
Xno reason for you to keep subscribing to an insecure model of resource
Xsharing.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XAlthough pty will put an entry into utmp, it doesn'\''t really support
Xthe remote-host field. There is no logical association between sessions
Xand connections; why should a login require a pty, and why should a
Xsession only stick around for one connection? So pty just puts "pty" in
Xthe host field. You can change this with -DPTYUTMP_HOST=\"foo\"; you may
Xeven want to make PTY_UTMPHOST call a function that you define.
X
X(Similar comments apply to PTYWTMP_HOST. There are also PTYUTMP_SWHOST
Xand PTYWTMP_SWHOST, defaults PTYUTMP_HOST and "pty-sessuser"
Xrespectively; see util/sessuser.1 for more information.)
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
X/usr/adm/wtmp has traditionally recorded all logins, logouts, reboots,
Xftp sessions, and various other interesting events. (The entry for a
Xline in utmp is the last entry for that line in wtmp.) pty supports wtmp
Xfully, in the same way as utmp. You should make wtmp mode 644, owner
Xroot or pty as appropriate. Change PTYWTMP_FILE if /usr/adm/wtmp is
Xsomewhere else.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XYou can turn off utmp support by uncommenting the NO_UTMP line in
Xconfig.h. (Just delete the initial /*.) You can also turn off support
Xfor wtmp, disconnectable sessions, or changing pseudo-terminal file
Xownership; just uncomment the appropriate line. You can force use of
Xeach of these features by defining MUST_UTMP, etc., in the same way.
X
XNote that the usual login programs do their own wtmp management, and
Xmany accounting programs incorrectly equate session time with connect
Xtime, so users will rarely want wtmp. As more programs appear using the
Xpty interface, and as login programs start using a more logical system
Xfor accounting, MUST_WTMP may become an appropriate way to monitor
Xpseudo-terminal usage. For the moment, I do not advise setting any NO
Xor MUST.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
Xpty subscribes (not very willingly) to the BSD 4.3 model of pty
Xprotection, with a few twists. All ptys are under group tty, at all
Xtimes; if you don'\''t have a tty group, all ptys should be under some
Xother protected group at all times. Anyway, pty will change the group of
Xeach pseudo-terminal file to PTYGROUP, default 4, under -xc.
X'
X
Xcase "$ttygroup" in
X4) echo '
XSince you already have a tty group, gid 4, you'\''re fine.
X' ;;
X'') echo '
XYou don'\''t have a tty group. You should pick a gid and define
X-DPTYGROUP=whatever in the Makefile.
X' ;;
X*) echo '
XYou have a tty group, but it'\''s not gid 4. You should define
X-DPTYGROUP='"$ttygroup"' in the Makefile.
X' ;;
Xesac
X
Xecho '
X(Under Case UN, don'\''t worry about all this group stuff. Just leave
XPTYGROUP alone.)
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XUnder -xc, pty changes the pseudo-terminal owner to the current real
Xuid. The fact that terminals need to be in the file hierarchy reflects a
Xserious failure in the BSD terminal model; but anyway, many programs
Xexpect to be able to fool around with /dev/tty. After pty is done with
Xthe terminal, it sets the owner back to its effective uid. You can
Xmodify this behavior by changing PTYOWNER from euid to something else.
X
XUnder Case UN, PTYOWNER is irrelevant.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XWhile a tty is unused, BSD systems traditionally leave it unprotected.
XUnfortunately, this leaves some huge security holes. Here'\''s one of
Xthe biggest advantages of a privileged pty manager: unused ttys don'\''t
Xhave to be left open for any random program to use. After it'\''s done
Xwith a pseudo-terminal, pty changes it to mode UNUSEDPTYMODE, default
X0600. (This is another case of a poor model for kludging pty support
Xinto unprivileged programs. If you haven'\''t set up separate pty banks
Xfor pty, and you really want to allow unprivileged access to unused
Xptys, try mode 0660 and make those other programs setgid to tty.)
X
XA tty that someone'\''s using can be in many different modes. Typically
XUSEDPTYMODE should be 0600, which means user-only access, messages off,
Xbiff off. If you really, really, really want to make the mistake of
Xhaving messages or biff on by default, try 0620, 0700, or 0720. Note
Xthat the world protection should always be 0: the point of the tty group
Xis that only setgid-tty programs can access ttys.
X
XAs usual, you can'\''t do anything about these in Case UN.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XNow we'\''re past generic configuration and down to your system'\''s
Xnitty-gritty.
X
XFor purity, pty has SIGRET_TYPE, default int, as the type returned by a
Xsignal handler. On Suns and ANSI-compliant machines, you should define
XSIGRET_TYPE=void. Then you can admire the lint -haxc *.c output.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XOUTBUFSIZE, default 16384, is the size of the buffer pty keeps between
Xthe incoming data and the pseudo-tty, and between the pseudo-tty and the
Xoutgoing data. If you want to spare less than 32K per pty just for
Xbuffer space, feel free to change this.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XGENERIC is another concession to ANSI taste. GENERIC * should be a
Xpointer type that any other pointer can be safely converted to and back;
XGENERIC is char by default, but on newer machines can be set to void.
XAs it'\''ll be at least five years before ANSI manages to outlaw char *,
Xand as void * is often invalid, I advise you to leave GENERIC alone.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
Xpty attempts to forward window-size changes transparently. It also
Xsupports the auxiliary characters structure, wÀ€µze'
Xif man 4 tty | sed 's/_//g' | grep -s winsize
Xthen havewin=y; echo '
XI see you have window sizes.
X'
Xelse havewin=n; echo '
XI see you don'\''t have window sizes.
XYou'\''ll have to comment out #define TTY_WINSIZE in config.h.
X(This may be inaccurate on Suns; try grep winsize /usr/include/sys/tt*.h.)
X' 
X     case "$ttygroup" in
X     4) ;;
X     '') echo '(Let me guess: This isn'\''t a BSD 4.3 system.)' ;;
X     *) ;;
X     esac
Xfi
X
Xecho 'Running $ man 4 tty | sed '\''s/_//g'\'' | grep -s auxchars'
Xif man 4 tty | sed 's/_//g' | grep -s auxchars
Xthen haveaux=y; echo '
XI see you have auxiliary characters.
XYou should uncomment #define TTY_AUXCHARS in config.h.
X'
Xelse haveaux=n; echo '
XI see you don'\''t have auxiliary characters.
X'
Xfi
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
Xpty also puts siginterrupt() and usleep() to good use in working
Xaround BSD limitations. Without siginterrupt(), there is absolutely
Xno way to get per-process non-blocking I/O, so pty may block when it
Xdoesn'\''t have to (namely, when it has N bytes to write to the output,
Xthe output is a pipe with M bytes of space, and N > M > 0). If you
Xdefine SIGINTERRUPT (as default), pty will take some extra effort to
Xnever, ever, ever block when it doesn'\''t have to.
X
XAt one point, pty pauses to kludge around a common bug in UNIX-domain
Xsockets. With usleep() it will pause much more briefly. This makes
Xreconnects much faster.
X'
X
Xecho 'Running $ man siginterrupt | sed '\''s/_//g'\'' | grep -s siginterrupt'
Xif man siginterrupt | sed 's/_//g' | grep -s siginterrupt
Xthen havesigintr=y; echo '
XI see you have siginterrupt(). Good.
X'
X     case "$ttygroup$havewinsize" in
X     4y) echo 'I'\''ll bet you'\''re a BSD 4.3 system.' ;;
X     *) echo 'Weird, are you BSD 4.3?' ;;
X     esac
Xelse havesigintr=n; echo '
XI see you don'\''t have siginterrupt(). You have to comment out
X#define SIGINTERRUPT in config.h.
X'
Xfi
X
Xecho 'Running $ man usleep | sed '\''s/_//g'\'' | grep -s usleep'
Xif man usleep | sed 's/_//g' | grep -s usleep
Xthen haveusleep=y; echo '
XI see you have usleep(). Good.
X'
Xelse haveusleep=n; echo '
XI see you don'\''t have usleep(). You have to comment out
X#define USLEEP in config.h.
X'
Xfi
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XFinally (almost done with configuration!), we have to make sure that you
Xhave UNIX-domain sockets, and check whether you have file descriptor
Xpassing.
X'
X
Xecho 'Running $ test -r /usr/include/sys/un.h'
Xif test -r /usr/include/sys/un.h
Xthen haveunsocks=y; echo '
XI see you have UNIX-domain sockets. Good.
X'
X   echo 'Running $ man recvmsg | sed '\''s/_//g'\'' | grep -s rights'
X   if man recvmsg | sed 's/_//g' | grep -s rights
X   then havefdpass=y; echo '
XI see you have file descriptor passing. Good. (Your fd passing may be
Xbuggy, as it'\''s a relatively new, powerful, and rarely exploited
Xfeature. If you have trouble, try defining NO_FDPASSING.)
X'
X   else havefdpass=n; echo '
XI see you don'\''t have file descriptor passing. This isn'\''t a
Xdisaster, though it means that reconnected sessions will be as
Xinefficient as they are in programs other than pty, boo hoo hoo.
XUncomment NO_FDPASSING in config.h.
X'
X   fi
Xelse haveunsocks=n; echo '
XUh-oh. I don'\''t see <sys/un.h>, which means you probably don'\''t have
XUNIX-domain sockets. Without sockets you can'\''t have disconnectable
Xsessions. Sigh. I guess you have to define NO_UNIXSOCKS in config.h.
X'
Xfi
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XWhew! We'\''ve finally made it through configuration. If you want, try
Xrunning lint -haxc *.c or whatever your favorite code checker is; the
Xlint here gives some bogus errors about correct char * casts, an error
Xbecause the SIG_IGN definition is unportable, and a couple of bzero
Xcomplaints because FD_ZERO isn'\''t defined very well.
X
XIf you'\''re on an old system without FD_ZERO, FD_SET, and FD_ISSET in
X<sys/types.h>, I recommend you upgrade. Try copying file.h.old to file.h
X(the original version is in file.h.new).
X
XWe'\''re nearly at the end. Change CC and CCOPTS in the Makefile for any
Xlast-minute additions; if you'\''re worried, change -s to -g for debugging.
XNow compile! % (date; make) >>& Makelog & and come back to this script.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XWhile the program is compiling, let'\''s start providing some support.
X(If the compile finishes or has an error, just ignore it for the
Xmoment.) These are some real changes, so watch out!
X
XFirst---in Case PTY only!---make a new uid, pty, not allowing logins.
X
X/etc/passwd:  pty:*:whatever:4:::/bin/true
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XSecond, make sure you have a tty group set up.
X
X/etc/group:  tty:*:4:root
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XThird, make PTYDIR.
X
XROOT: # mkdir /usr/etc/pty; chmod 700 /usr/etc/pty
XPTY: # mkdir /usr/etc/pty; chown pty /usr/etc/pty; chmod 700 /usr/etc/pty
XUN: % mkdir ~/PTY; chmod 700 ~/PTY
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XFourth, make sure you have all the pseudo-terminal files set up and
Xappropriately configured.
X
XChange each of them to group tty.
X
XChange each of them to owner pty in case PTY or root in case ROOT.
X
XChange each of them to mode UNUSEDPTYMODE (0600).
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XFifth, make sure /etc/utmp and /usr/adm/wtmp exist, owned by root in
XCase ROOT or pty in Case PTY, each mode 644. (In Case UN, you probably
Xwant to be working on a Sun with its insecure /etc/utmp, so that pty can
Xtake advantage of it. Sigh.)
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XSixth, I advise that you make a special directory /usr/local/ptybin for
Xpty and its associated utilities, with symbolic links in /usr/local.
XThis choice isn'\''t too important, but it'\''s easier if you know a
Xplace to put programs.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XOkay. You'\''ve done about all that can be done before compilation
Xfinishes, so go do something else.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XThe compile should be done now. If all went well, the make should have
Xexited normally, Makelog should show no errors, and you should have an
Xexecutable pty program sitting in this directory. Unfortunately, life
Xisn'\''t always so generous. Here are a few of the more common errors.
X
XThe loader complains about missing getopt(), optarg, and optind: These
Xare all in the getopt library, available in the early volumes of
Xcomp.sources.unix. If you use GNU getopt, please make sure you
Xunderstand the implications of its license.
X
XThe loader complains about missing FD_ZERO, FD_SET, and FD_ISSET: Try
Xcopying file.h.old to file.h and recompiling. If the compiler gives
Xvarious further errors related to these macros, uncomment the
Xcommented-out lines in file.h.old, copy to file.h, and try once again.
X
Xbcopy() isn'\''t defined: In pty.h, change bcopy(src,dst,num) to
Xmemcpy(dst,src,num). (Note the order.) Try again.
X
XIf you still can'\''t get the code to compile, let the author know.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XNext, compile the utilities. There isn'\''t much to say about them;
Xthey'\''re all public domain, some of them clones of or improvements
Xover standard utilities, some of them clones with special features to
Xwork with pty, some of them entirely new programs for pty'\''s new
Xfeatures. Just glance at the top of util/Makefile; then
X% cd util; (date; make) >>& Makelog & and wait.
X
XWarning: The pty session directory is hardcoded in util/sessutil.c.
XIf you have changed PTYDIR, check through sessutil.c carefully.
X'
X
Xecho '----- Press return to continue. ' | tr -d '\012'; read contline
X
Xecho '
XSo now you should have some executables sitting around collecting dust.
XIn Cases ROOT and PTY, put {pty,biff,disconnect,mesg,reconnect,sesskill,
Xsesslist,sessname,sessuser} into a system-wide directory, owner root or
Xpty, mode 4755. Put wall and write into the same place, group tty, mode
X2755. Put {condom,excloff,exclon,last,lock,script,script.tidy,sess,tiocsti,
Xtty,u,who,xdisconnect,xreconnect,xsesskill,xsesslist,xsessname,xsessuser}
Xinto the same place, mode 755. Make absolutely sure none of the shell
Xscripts are setuid.
X
XIn Case UN, just put all the programs somewhere in your PATH.
X
XThat'\''s it! Try running TESTS now.
X
X(Two other things you have to do at some point: move your old script,
Xbiff, mesg, and so on to script.old, biff.old, mesg.old, etc., with
Xsymbolic links to the new versions in their place; and move the old
X/usr/man/{script,biff,mesg,...}.1 somewhere else, copy all the *.1
Xhere to /usr/man/man1, and run /etc/catman.)
X'
END_OF_FILE
echo shar: note: \"'INSTALL.ctrl'\" contains 10 control characters
if test 25242 -ne `wc -c <'INSTALL.ctrl'`; then
    echo shar: \"'INSTALL.ctrl'\" unpacked with wrong size!
fi
chmod +x 'INSTALL.ctrl'
# end of 'INSTALL.ctrl'
fi
if test -f 'util/lock.c.ctrl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'util/lock.c.ctrl'\"
else
echo shar: Extracting \"'util/lock.c.ctrl'\" \(852 characters\)
sed "s/^X//" >'util/lock.c.ctrl' <<'END_OF_FILE'
X/* Public domain. */
X#include <curses.h>
X#include <signal.h>
X#include <strings.h>
X
Xmain()
X{
X char key[100];
X char key2[100];
X struct sigvec vec;
X int i;
X
X vec.sv_handler = SIG_IGN;
X vec.sv_mask = 0;
X for (i = 31;i > 0;i--)
X   (void) sigvec(i,&vec,(struct sigvec *) 0);
X (void) savetty();
X (void) crmode();
X (void) noecho();
X (void) printf("Key: ");
X if (fgets(key,sizeof(key) - 2,stdin))
X  {
X   (void) printf("\nAgain: ");
X   if (fgets(key2,sizeof(key2) - 2,stdin))
X    {
X     if (!strcmp(key,key2))
X      {
X       (void) printf("\n");
X       while ((fgets(key2,sizeof(key2),stdin) == NULL) || strcmp(key,key2))
X	{
X	 (void) printf("Bad password!\n");
X	 (void) sleep(1);
X	}
X      }
X     else (void) printf("\n");
X    }
X   else (void) printf("\n");
X  }
X else (void) printf("\n");
X (void) resetty();
X (void) exit(0);
X /*NOTREACHED*/
X}
END_OF_FILE
echo shar: note: \"'util/lock.c.ctrl'\" contains 20 control characters
if test 852 -ne `wc -c <'util/lock.c.ctrl'`; then
    echo shar: \"'util/lock.c.ctrl'\" unpacked with wrong size!
fi
# end of 'util/lock.c.ctrl'
fi
if test -f 'util/script.tidy.ctrl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'util/script.tidy.ctrl'\"
else
echo shar: Extracting \"'util/script.tidy.ctrl'\" \(63 characters\)
sed "s/^X//" >'util/script.tidy.ctrl' <<'END_OF_FILE'
X#!/bin/sh
X# Public domain.
Xexec sed -e 's/$//' -e 's/[^]//g'
END_OF_FILE
echo shar: note: \"'util/script.tidy.ctrl'\" contains 2 control characters
if test 63 -ne `wc -c <'util/script.tidy.ctrl'`; then
    echo shar: \"'util/script.tidy.ctrl'\" unpacked with wrong size!
fi
chmod +x 'util/script.tidy.ctrl'
# end of 'util/script.tidy.ctrl'
fi
if test -f 'util/wall.c.ctrl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'util/wall.c.ctrl'\"
else
echo shar: Extracting \"'util/wall.c.ctrl'\" \(1577 characters\)
sed "s/^X//" >'util/wall.c.ctrl' <<'END_OF_FILE'
X/* Public domain. */
X
X#include <sys/types.h>
X#include <sys/timeb.h>
X#include <sys/file.h>
X#ifdef BSD
X#include <limits.h>
X#endif
X#include <stdio.h>
X#include <strings.h>
X#include <utmp.h>
X#include <pwd.h>
X#include <time.h>
X#include <ctype.h>
Xextern unsigned short getuid();
Xextern char *ttyname();
Xextern long time();
X#define PTYUTMP_FILE "/etc/utmp"
X
Xmain()
X{ 
X register FILE *fi;
X struct utmp ut;
X char fntty[30];
X int fd;
X char buf[10000];
X char *username;
X struct passwd *pw;
X char hostname[64];
X char *ttyn;
X long t;
X struct tm *tm;
X int r;
X int pos;
X
X if (!(pw = getpwuid((int) getuid())))
X  {
X   (void) fprintf(stderr,"write: who are you?\n");
X   (void) exit(1);
X  }
X username = pw->pw_name;
X
X (void) gethostname(hostname,sizeof(hostname));
X
X if (!(ttyn = ttyname(2)))
X  {
X   (void) fprintf(stderr,"wall: Can't find your tty\n");
X   (void) exit(1);
X  }
X
X t = time((long *) 0);
X tm = localtime(&t);
X
X (void) sprintf(buf,"\nBroadcast message from %s@%s on %s at %d:%02d ...\n\n",
X		username,hostname,ttyn + 5,tm->tm_hour,tm->tm_min);
X pos = strlen(buf);
X (void) write(1,buf + 1,pos - 1);
X while ((pos < 10000) && ((r = read(0,buf + pos,10000 - pos)) > 0))
X   pos += r;
X
X if (fi = fopen(PTYUTMP_FILE,"r"))
X   while (fread((char *) &ut,sizeof(ut),1,fi))
X     if (ut.ut_name[0])
X      {
X       (void) sprintf(fntty,"/dev/%.8s",ut.ut_line);
X       if ((fd = open(fntty,O_WRONLY)) == -1)
X         (void) fprintf(stderr,"wall: cannot write to %.8s\n",ut.ut_line);
X       else
X        {
X	 (void) write(fd,buf,pos);
X         (void) close(fd);
X        }
X      }
X
X (void) exit(0);
X}
END_OF_FILE
echo shar: note: \"'util/wall.c.ctrl'\" contains 1 control character
if test 1577 -ne `wc -c <'util/wall.c.ctrl'`; then
    echo shar: \"'util/wall.c.ctrl'\" unpacked with wrong size!
fi
# end of 'util/wall.c.ctrl'
fi
if test -f 'util/write.c.ctrl' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'util/write.c.ctrl'\"
else
echo shar: Extracting \"'util/write.c.ctrl'\" \(2728 characters\)
sed "s/^X//" >'util/write.c.ctrl' <<'END_OF_FILE'
X/* Public domain. */
X
X#include <sys/types.h>
X#include <sys/timeb.h>
X#include <sys/stat.h>
X#include <sys/file.h>
X#ifdef BSD
X#include <limits.h>
X#endif
X#include <stdio.h>
X#include <strings.h>
X#include <utmp.h>
X#include <pwd.h>
X#include <time.h>
X#include <ctype.h>
Xextern unsigned short getuid();
Xextern char *ttyname();
Xextern long time();
X#define PTYUTMP_FILE "/etc/utmp"
X
Xmain(argc,argv)
Xint argc;
Xchar *argv[];
X{ 
X register FILE *fi;
X struct utmp ut;
X char line[9];
X int lines = 0;
X char fntty[30];
X int fd;
X struct stat st;
X char buf[500];
X int offset;
X char *username;
X struct passwd *pw;
X char hostname[64];
X char *ttyn;
X long t;
X struct tm *tm;
X char *s;
X
X if (argc < 2)
X  {
X   (void) fprintf(stderr,"Usage: write user [ttyname]\n");
X   (void) exit(1);
X  }
X
X if (!(pw = getpwuid((int) getuid())))
X  {
X   (void) fprintf(stderr,"write: who are you?\n");
X   (void) exit(1);
X  }
X username = pw->pw_name;
X
X (void) gethostname(hostname,sizeof(hostname));
X
X if (!(ttyn = ttyname(2)))
X  {
X   (void) fprintf(stderr,"write: Can't find your tty\n");
X   (void) exit(1);
X  }
X
X t = time((long *) 0);
X tm = localtime(&t);
X
X if (fi = fopen(PTYUTMP_FILE,"r"))
X   while (fread((char *) &ut,sizeof(ut),1,fi))
X     if (!strncmp(ut.ut_name,argv[1],8))
X       if ((argc == 2) || (!strncmp(ut.ut_line,argv[2],8)))
X	 if (!lines)
X	  {
X	   (void) strncpy(line,ut.ut_line,8);
X	   line[8] = '\0';
X	   lines = 1;
X	  }
X	 else
X	   lines++;
X if (!lines)
X  {
X   if (argc == 2)
X     (void) fprintf(stderr,"write: %s not logged in\n",argv[1]);
X   else
X     (void) fprintf(stderr,"write: %s not logged in on tty %s\n",
X		    argv[1],argv[2]);
X   (void) exit(1);
X  }
X if (lines > 1)
X   (void) fprintf(stderr,
X   "write: %s logged in more than once ... writing to %s\n",
X   argv[1],line);
X
X (void) sprintf(fntty,"/dev/%s",line);
X if ((fd = open(fntty,O_WRONLY)) == -1)
X  {
X   (void) fprintf(stderr,"write: Permission denied\n");
X   (void) exit(1);
X  }
X
X (void) sprintf(buf,"\nMessage from %s@%s on %s at %d:%02d ...\n",
X		username,hostname,ttyn + 5,tm->tm_hour,tm->tm_min);
X (void) write(fd,buf,strlen(buf));
X
X (void) sprintf(buf,"%s: ",username);
X offset = strlen(buf);
X
X while (fgets(buf + offset,sizeof(buf) - offset,stdin))
X  {
X   (void) fstat(fd,&st);
X   if (!(st.st_mode & 0020))
X    {
X     (void) fprintf(stderr,"write: Permission denied\n");
X     (void) exit(1);
X    }
X   for (s = buf;*s;s++)
X     if (((!isascii(*s) || !isprint(*s))) && (*s != '\n'))
X       *s = '^';
X   (void) write(fd,buf,strlen(buf));
X   (void) sleep(1);
X  }
X
X t = time((long *) 0);
X tm = localtime(&t);
X (void) sprintf(buf,"End of message from %s@%s on %s at %d:%02d\n",
X		username,hostname,ttyn + 5,tm->tm_hour,tm->tm_min);
X (void) write(fd,buf,strlen(buf));
X
X (void) exit(0);
X}
END_OF_FILE
echo shar: note: \"'util/write.c.ctrl'\" contains 1 control character
if test 2728 -ne `wc -c <'util/write.c.ctrl'`; then
    echo shar: \"'util/write.c.ctrl'\" unpacked with wrong size!
fi
# end of 'util/write.c.ctrl'
fi
echo shar: Moving bad files out of the way and good files in:
echo shar: INSTALL to INSTALL.bad
echo shar: INSTALL.ctrl to INSTALL
mv INSTALL INSTALL.bad
mv INSTALL.ctrl INSTALL
echo shar: util/lock.c to util/lock.c.bad
echo shar: util/lock.c.ctrl to util/lock.c
mv util/lock.c util/lock.c.bad
mv util/lock.c.ctrl util/lock.c
echo shar: util/wall.c to util/wall.c.bad
echo shar: util/wall.c.ctrl to util/wall.c
mv util/wall.c util/wall.c.bad
mv util/wall.c.ctrl util/wall.c
echo shar: util/write.c to util/write.c.bad
echo shar: util/write.c.ctrl to util/write.c
mv util/write.c util/write.c.bad
mv util/write.c.ctrl util/write.c
echo shar: util/script.tidy to util/script.tidy.bad
echo shar: util/script.tidy.ctrl to util/script.tidy
mv util/script.tidy util/script.tidy.bad
mv util/script.tidy.ctrl util/script.tidy
echo shar: End of shell archive.
exit 0
