#! /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:  README INSTALL Makefile srialpop.c
# Wrapped by rudi@speelman on Tue Nov 12 09:59:13 1996
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'README' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'README'\"
else
echo shar: Extracting \"'README'\" \(10061 characters\)
sed "s/^X//" >'README' <<'END_OF_FILE'
X
X        S R I A L P O P -- POP over serial lines
X        (sccs info README 2.4 96/10/09)
X
X        Author: Rudi van Houten <R.vanHouten@cc.ruu.nl>
X                Ac.Comp.Centr.Utrecht (Netherlands)
X        With thanks to:
X                Steve Dorner <sdorner@qualcomm.com>
X                Scott Hannahs <sth@slipknot.mit.edu>
X                Mogen Trab Damsgaard <trab@kubism.ku.dk>
X
X========================== COPYRIGHT NOTICE =============================
XThis package srialpop is written by and copyright Rudi van Houten
X<R.vanHouten@cc.ruu.nl>, it is tested and used now at ACCU (Ac.Comp.
XCentr.Utrecht, the Netherlands) for several years.
X
XThe package consists of four files:
X    srialpop.c  the C source of the program
X    Makefile    to build and eventually install the package
X    README      an old documentation describing the package
X    INSTALL     a newer document with concise installation instructions
X
XI grant everybody the right to use the package and eventually
Xadapt it to local requirements. Please document your changes in the
Xprogram source with comments explicitely stating that a modification
Xto the original package has been made. I don't want to be blamed for
Xyour errors nor get the praise for your inventions.
X
XAlso everybody has the right to bundle this package with other software
X(e.g. a POP client) on distribution media, but THEN THE UNCHANGED VERSION
XMUST BE DISTRIBUTED, and no extra fee may be charged for the presence
Xof srialpop in the bundle. If there is a need to modify srialpop for
Xspecial purposes these modification should be made available as a separate
Xfile (e.g. a diff file to be applied with Larry Wall's patch program).
X
XI present this package as is, feeling it can be of use. But no
Xguarantees are given about its proper working or behaviour. It has
Xbeen used at ACCU for some years now without troubles, so I think it may
Xbe bug free. But I cannot be held responsible for any damage or other
Xmisery resulting from using srialpop.
X===========================================================================
X
X    The Macintosh POPmail client Eudora offers a possibility
X    to perform the POP and SMTP conversations over a serial
X    (dialup) connection. Therefore is needed a 'psuedo-account'
X    on a machine where Eudora can login. That account must have
X    permission to execute senndmail and popper, not only local
X    but also remote (via rsh) on all machines where a popserver
X    or smtpserver must be contacted. Eudora is secretive with
X    the password while showing its progress (if properly
X    configured), but nobody can prevent a curious Macontosh
X    owner from looking with ResEdit (or alike's). It can be a
X    security leak.
X    The same considerations apply to the IBM-PC client NUPop
X    that also can use serial tty-lines to acquire mail.
X    
X    This program srialpop is written to take care of these
X    trade off's. It must be used as the pseudo-account's
X    loginshell. The commands which are recognized by the
X    program are 'logout' and 'exit' (to finish the session
X    of course) and 'telnet <host> <port> ...' which performs
X    a TCP/IP connection with the indicated host/port. The
X    supplied portnumber is checked against a list of valid
X    portnumbers (now only POP, SMTP, PH and PASSWD).
X    All other commands cause an exit with errormessage.
X    
X    So the pseudo-account doesn't need permissions to run
X    popper and sendmail, neither needed are permissions to
X    run rsh to another machine or let another machine rsh
X    in. And a diligent POPmail user who tries to login on
X    the psuedo-account will discover that there is no fun.
X    Since nobody can be prevented to learn srialpop's
X    password it is mandatory that the home directory for
X    pseudo-user srialpop is unwritable for srialpop.
X    
X    The program is straightforward and rather simple, and
X    it is free. Yet I claim a copyright, with which I mean
X    that anybody who feels a need to change (parts of) this
X    program is under the obligation to document the changes
X    and the need thereof in the program distribution files.
X    Neither may this program be selled (as if anybody would
X    buy this gadget), or distributed for a fee that extends
X    a reasonable retribution for the 8k it occupies on disk
X    or other media (I don't ask money, why should you).
X    I have tested the program for some time now and found no
X    bugs/problems. That doeesn't mean of course there are not.
X    I offer this program free for everyone to use because I
X    think it can be useful and is less dangerous then the
X    shellscript originally suggested by Steve Dorner. But if
X    you stumble over an error I am in no way responsible for
X    the damage that can cause, however I don't expect disasters.
X    I should welcome (by email) any notification of changes,
X    corrections and enhancements in the form of the new program
X    source or a diff.
X
X    At A.C.C.U. we rent POP mailboxes to users as a special cheap
X    service. The users who obtain that service can only use email
X    via the POP/SMTP mechanism. The owner of a POPmail account
X    can not do any work on the UNIX machine, only change his/her
X    password (their login shell is a script that consists of a
X    call to /bin/passwd), and they don't need a home directory.
X    Hence the service can be cheap.
X
X    The passwd entry for pseudo-user srialpop is:
X    (splitted for layout reasons)
X    srialpop:passwd:uid:gid:POP dialup dummy account:\
X                        /home/srialpop:/home/srialpop/srialpop
X
X    The passwd entry for a POPmail account:
X    popuser:passwd:uid:gid:POPmailuser:/home/srialpop:/usr/local/etc/chpw
X
X    And the script /usr/local/etc/chpw used as their loginshell:
X    #!/bin/sh
X    exec /bin/passwd
X
X    (Or place /bin/passwd as "loginshell" in /etc/passwd)
X    
X    Rudi van Houten  <rudi@cc.ruu.nl>
X    Ac.Comp.Centr.Utrecht
X    Budapestlaan 6
X    3584 CD Utrecht Netherlands
X
X    ********************
X    Known bugs:
X
X    **NOTE for NUPop users **
X    If srialpop is used the end-of-line indicator must be set
X    to "^M^J" in the "Options -> Serial" menu of NUPop.
X    ****
X
X    There are some quirks with end-of-line definitions.
X    TCP/IP requires CR-LF (according to the RFC's), but I
X    never encountered a TCP/IP connection that was not satisfied
X    with only LF.
X    Someone reported that his system produced and accepted an
X    end-of-line consisting of LF-CR, I didn't save the mails and
X    forgot the details.
X    When using public datanet systems (as X.25 in Europe) there
X    can be a problem that X.25 considers CR as end-of-packet and
X    the LF that is sent thereafter by the UNIX-system or POP-client
X    is then considered as the start of a new packet, that never is
X    closed. When I will have some time to spare I will look at that,
X    but perhaps someone else will find a solution earlier (I expect
X    it can be solved by setting appropriate LF-CR translations in
X    srialpop and defining a single CR as end-of-line in Eudora/NUPop).
X
X
X    Program history:
X    9 dec 91   original version, only installed at ACCU
X               The distribution contains one file 'srialpop.c'
X    11 dec 91  some changes in IO-handling after Steve Dorner
X               viewed the program and made some sugeestions
X    - V1.0-
X    18 aug 92  added port 105 for PH service
X    20 Oct 92  changes for conditional compilation on Silicon
X               Graphics sent in by Scott Hannahs
X               <sth@slipknot.mit.edu>
X    - V1.1-
X    22 Nov 92  added a wait time before exit to satisfy the
X               Macintosh CTB Hayes Modem Tool.
X               added port 106 for password service
X               Introduce the use of a make to enable simple
X               definitions of symbols.
X    14 dec 92  added exclusion of tab expansion
X               (Mogen Trab Damsgaard <trab@kubism.ku.dk>)
X    - V1.2-
X    8 June 93  now change the terminal settings for the whole
X               life of the program. Read the commands in blocks
X               of one character and do the echo from the program.
X    - V1.3-
X    15 June 93 V1.2 did send the second character of CR-LF (or 
X               LF-CR) line-end from the telnet command to the
X               connected server via the socket. This character
X               is now catched and thrown away. Some popservers
X               couldn't handle this, but I didn't see this
X               since popper did not have troubles.
X    - V1.4-
X    12 July 93 Add logging capabilities.
X               If the logging on file is used be sure to create
X               a file srialpop.log in srialpop's home directory
X               that is writable by srialpop since srialpop is
X               unable to create a file there.
X    - V1.5-
X    sep 93     Add some remarks concerning ULTRIX in the README
X
XThis version of srialpop has been successfully tested on:
XConvex OS 10.1
XDEC (Philips) P9070 ATT SYS V/68 R3V6
X
XContinue the story:
X    - V2.0
X    aug 95      In the Makefile the values for logging and
X                flow control can be defined. Also code is
X                added to detect which include files (strings.h,
X                unistd.h, sgtty.h, termio.h, termios.h) must
X                be used.
X
X    - V2.1      interim release
X    - V-2.2 
X    apr '96		add NO_SMTP and file INSTALL (never released).
X    			If NO_SMTP is defined in the Makefile srialpop
X    			will not allow connection the the SMTP port (25).
X    			The POP clients must use the POP server to send mail.
X    - V2.3
X    oct '96		documentation changes, copyright notice.
X
XI have tried to install srialpop on the systems in the list below.
XThe systems marked with an asterisk (*) it is only compiled and tried
Xout via a telnet login but NOT actually tested on a tty port.
X
XConvex OS 9
XMotorola SYSTEM V/68 Release R3V6
XULTRIX 4.3 (*)
XSGI IRIX 5.4 (*)
XSunOS 4.1.3
XSolaris 2.4 (Sun Sparc only) (*)
XIBM AIX 3.21 and 4.1
XDEC Alpha OSF/1 3.0 (*)
X
XSome friends of mine have tried the Makefile and compilation on Linux.
XWithout problems, but they didn't test the results.
END_OF_FILE
if test 10061 -ne `wc -c <'README'`; then
    echo shar: \"'README'\" unpacked with wrong size!
fi
# end of 'README'
fi
if test -f 'INSTALL' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'INSTALL'\"
else
echo shar: Extracting \"'INSTALL'\" \(14325 characters\)
sed "s/^X//" >'INSTALL' <<'END_OF_FILE'
X    INSTALL  2.6 96/11/12
X
X    S R I A L P O P
X
X    Concise installation guide.
X
X    =============================================
X
X    Contents:
X    - COPYRIGHT NOTICE
X    1.What is srialpop?
X    2.Why should you use it?
X    3.How to install srialpop:
X    4.Are there disadvantages in using srialpop?
X    5.Has srialpop security risks?
X    6.How to test srialpop:
X    7.Some navigation and scripting examples.
X
X    =============================================
X
X
X========================== COPYRIGHT NOTICE =============================
XThis package srialpop is written by and copyright Rudi van Houten
X<R.vanHouten@cc.ruu.nl>, it is tested and used now at ACCU (Ac.Comp.
XCentr.Utrecht, the Netherlands) for several years.
X
XThe package consists of four files:
X    srialpop.c  the C source of the program
X    Makefile    to build and eventually install the package
X    README      an old documentation describing the package
X    INSTALL     a newer document with concise installation instructions
X
XI grant everybody the right to use the package and eventually
Xadapt it to local requirements. Please document your changes in the
Xprogram source with comments explicitely stating that a modification
Xto the original package has been made. I don't want to be blamed for
Xyour errors nor get the praise for your inventions.
X
XAlso everybody has the right to bundle this package with other software
X(e.g. a POP client) on distribution media, but THEN THE UNCHANGED VERSION
XMUST BE DISTRIBUTED, and no extra fee may be charged for the presence
Xof srialpop in the bundle. If there is a need to modify srialpop for
Xspecial purposes these modification should be made available as a separate
Xfile (e.g. a diff file to be applied with Larry Wall's patch program).
X
XI present this package as is, feeling it can be of use. But no
Xguarantees are given about its proper working or behaviour. It has
Xbeen used at ACCU for some years now without troubles, so I think it may
Xbe bug free. But I cannot be held responsible for any damage or other
Xmisery resulting from using srialpop.
X===========================================================================
X
X
X1.What is srialpop?
X------------------
X
X  Srialpop is a little gadget running on a UNIX system that makes a
X  serial terminal connection to a UNIX system (tty port) behave like
X  a TCP/IP connection. It was written to support the Post Office
X  Protocol (POP) over serial dial up lines for use with Eudora and
X  NUPop. Hence the name srialpop.
X  See also the file README.
X
X2.Why should you use it?
X-----------------------
X
X  In these days of SLIP and PPP, and IP over ISDN, the need of a gadget
X  like srialpop is fastly dwindling.
X  You only need srialpop if:
X  -your connection from your personal computer (Mac or PC) to the
X   maildrop computer is a plain serial tty connection. Either directly
X   to your mailhost or via a portselector (eg. Develcon or Gandalf).
X  -you connect to a communication server (Annex, Cisco, AccessBuilder)
X   that only offers the possibility to set up an interactive login session.
X
X  In short, if you are limited to a connection that shows you the UNIX
X  login prompt when the connection is established then you need srialpop.
X
X  You don't need srialpop if:
X  -your personal computer is connected to the mailhost via a TCP/IP
X   network.
X  -you use SLIP or PPP to reach the mailhost with a TCP/IP connection.
X  -you can connect to a communication server that enables you to open
X   a TCP/IP connection for POP and SMTP.
X
X  If this documentation doesn't provide you with enough clues to decide
X  you need or don't need srialpop please contact your UNIX system or
X  network manager.
X  If you decide you need srialpop but it is not clear how you should
X  install it you also need to call the help of your UNIX or network
X  manager.
X
X3.How to install srialpop:
X-------------------------
X
X  First you must compile srialpop on your mailhost UNIX system. I have
X  concocted a Makefile that ought to work on most systems. Perhaps
X  you might prune it somewhat. Especially the owner uid/gid should be
X  adapted to your situation. When srialpop is successfully made with
X  the command "make" you have to install it somewhere on the system.
X  There exist some different approaches to make it usable:
X  -You are not a system manager and you are installing srialpop for
X   your personal use. In this case you must move the srialpop executable
X   to your personal bin directory (generally $HOME/bin) that is named in
X   your searchpath (PATH in [ba|k]sh or path in [t]csh). If your
X   .profile ([ba|k]sh) or .login ([t]csh) interactively asks questions, eg.
X   the tset command, you have to teach the Eudora navigation or NUPop
X   scripts to handle these questions. Consult your POP client docs
X   on how to do this.
X   The command to perform this installation (I assume you have already
X   unpacked the files since you are reading this INSTALL):
X        make instbin
X   This installs srialpop in your ${HOME}/bin directory.
X   You can also use:
X        make
X        cp srialpop $HOME/bin (assuming you have this directory)
X        strip $HOME/bin/srialpop
X        chmod 755 $HOME/bin/srialpop
X  -You are a system manager and you are installing srialpop for general
X   use. Of course you can then simply install the srialpop binary in the
X   public bin directory (generally /usr/local/bin). This has the same
X   disadvantages concerning the questions in .profile or .login as with
X   the installation for personal use described above.
X   The commands to perform this installation (I assume you have already
X   unpacked the files since you are reading this INSTALL):
X        su
X        make
X        mv srialpop /usr/local/bin (assuming you have this directory)
X        strip /usr/local/bin/srialpop
X        chmod 555 /usr/local/bin/srialpop
X        exit
X   However I prefer the next approach.
X  -You use the scheme followed in the Makefile at the target
X   "install:". Then before you run "make install" you must create a
X   user called srialpop that has the program ~srialpop/srialpop as
X   its login shell. Now everyone logging in as srialpop can use the
X   telnet commands allowed by srialpop (port 25, 105, 106 109 and 110).
X   This seems a security risk since it offers everyone and his/her dog
X   who can use a modem the possibility to enter the Internet on the
X   above mentioned ports. There is no way to keep the srialpop login
X   password hidden from the users. However, I don't consider this a
X   real risk. It does not really enlarge the access to Internet
X   considering the count of Internet Service Providers that offer
X   access to Internet, and srialpop limits the access to the above
X   mentioned services.
X   The advantage of this approach is that there is no interaction with
X   the user's .profile or .login. There is even no need for the users to
X   have a real home directory. At ACCU we now have some thousands of so
X   called POPmail accounts. These accounts have ~srialpop as home directory
X   and /bin/passwd (or /bin/false) as login shell.
X   The commands to perform this installation (I assume you have already
X   unpacked the files since you are reading this INSTALL):
X        make
X        su
X        <<create pseudo user srialpop and its home directory>>
X        make install
X        exit
X   See also the file README.
X
X4.Are there disadvantages in using srialpop?
X-------------------------------------------
X
X  Sure there is a disadvantage. The TCP/IP protocols are based upon
X  guaranteed faultless transmission. The POP clients don't provide
X  for error handling since it assumes no errors can occur with TCP/IP.
X  Also with SLIP and PPP this error free transmission is guaranteed.
X  With srialpop this is not so.
X  When you use srialpop the connection looks like TCP/IP to the client
X  program on your personal computer, but that is only a facade. Even
X  a modem with error correction (MNP4) can not ensure faultless
X  transmissions. There always is a small risk that errors show up.
X  In special sending big attachments with binhex or uuencode can cause
X  problems with unusable damaged mails.
X  Also there are some thoughts concerning security, real or imaginary.
X
X5.Has srialpop security risks?
X----------------------------
X  Yes, there are some aspects with srialpop considering security. The most
X  aspects are already mentioned.
X  -You can not be dead sure that messages will be transferred error free.
X  -The scheme with pseudo-user srialpop offers potential hackers a way
X   to use the TCP/IP ports allowed by srialpop without an authentication.
X   The normal ways to get access to Internet require an authentication
X   via an account on the host computer or communication server. But since
X   srialpop restricts the TCP/IP services to the set needed for mail
X   (SMTP/PH/poppasswd/POP2/POP3) I don't see reasons for alarm. And the
X   skilled hackers have means to reach the Internet in more unimpeded
X   ways. How else should they have acquired their skills?
X   But when you have shivers on this aspect don't use my preferred scheme.
X   SMTP is the only hairy one in srialpop's subset of allowed services, it
X   does not ask for authentication. You could reduce your shivers by
X   removing SMTP from that subset (NO_SMTP in the Makefile) and configure
X   the clients to use the POP server for sending mail. Of course both the
X   server software as the client software must then support this option.
X   See the documentation of your server and/or client software (look for
X   the POP3 extension "XTND XMIT").
X  -The login to account srialpop is automated in the scripts/navigation of
X   the POPmail client. When the telephone line is noisy and characters are
X   lost or maimed the login fails. Many UNIX systems (AIX, SCO) have a
X   policy of locking an account after repeated login failures. So for the
X   srialpop pseudo account this security policy must be disabled. Recently
X   we experienced at ACCU a storm of complaints that serial pop access was
X   suddenly impossible, it cost us an hour before we pinpointed that locking
X   as the cause of the problem.
X  -Also the use of an expiration time on passwords must be disabled for the
X   srialpop pseudo account. It is nearly impossible (and utterly senseless)
X   to advertise the change in password needed in the navigation scripts.
X  -Also remember that there are no ways to keep srialpop's password secret.
X   So everything in srialpop's home directory, including the home directory
X   itself must NOT be owned or being writable by srialpop and no sensitive
X   information must be kept in that directory.
X   If your flavour of UNIX supports it you should disable the possibility
X   to "su" to user srialpop. Also the program's pathname should NOT be defined
X   as an allowable shell (etc/shells on most systems, /etc/security/login.cfg
X   on AIX).
X  -If user srialpop is not disabled from using ftp there can be done dire
X   things with the SITE EXEC commands if your ftp-daemon allows it.
X   Therefore the "make install" will put user srialpop in /etc/ftpusers to
X   disable the use of ftp.
X   
X
X6.How to test srialpop:
X----------------------
X
X  Invoke the program srialpop, either by calling it from your own
X  login shell or by logging in as user srialpop. Srialpop will show
X  you the %-sign as prompt. Now you can enter commands just as in
X  a regular shell, but srialpop only allows the commands "exit",
X  "logout", "quit" and "telnet <host> <port>". The first three
X  commands will cause a graceful termination of srialpop. The
X  telnet-command will set up the desired telnet connection. Every
X  other command will result in an error exit.
X  When establishing a telnet connection srialpop performs its
X  magic on the tty settings as described in the file README. That
X  means echo-off and half-cooked mode. Now you can enter the
X  commands for the called IP service, but you will not see what
X  you type in (echo is off), and you must give a Linefeed (^J)
X  as line termination. In fact the line termination ought to be
X  the CR/LF (^M/^J) pair, but all UNIX systems I have tried till now
X  have been content with only the LF.
X  Upon closing the telnet connection the tty settings are set back to
X  what it was before.
X  This behaviour makes the program a little awkward for hand testing,
X  but it just is this functionality for what it was written.
X
X7.Some navigation and scripting examples.
X----------------------------------------
X
X  Macintosh Eudora uses STR#-resources for the "navigaton", see the
X  Eudora Users Manual Appendix D. An example of resources:
X  STR#-resource "Navigate In" ID=2400:
X      3 strings
X      string 1 "\r\r\elogin:"
X      string 2 "srialpop\r\eassword:"
X      string 3 "thepasswd\r\e%"
X   STR#-resource "Navigate Mid" ID=4200:
X      1 string
X      string 1 "\e%"
X   STR#-resource "Navigate Out" ID=2600
X      1 string
X      string 1 "logout\n"
X
X   NUPop uses script files MODEMINI.SCR, DIAL.SCR, CONNECT.SCR,
X   DISCONNE.SCR and DROP.SCR. Consult the NUPop documentation.
X   An example of a set of NUPop scripts:
X      MODEMINI.SCR:
X      *     Initialize the modem.
X      *
X      modeminit
X      
X      DIAL.SCR:
X      *
X      *     Initialize the modem.
X      *
X      modeminit
X      *
X      *     Dial terminal server / serving host
X      *
X      dial
X      *
X      *     Wait for "CONNECT" etc. to pass by.
X      *
X      *     Wait for the terminal server prompt.
X      *
X      * delay until login banner appears
X      repsendwait 2 2 "|" "login: "
X      *
X      * login as srialpop
X      stext "~srialpop|"
X      * wait for password prompt
X      waitstring "Password:"
X      * and send password
X      stext "~thepasswd"
X      * wait for command prompt
X      waitstring "%"
X      
X      CONNECT.SCR
X      *
X      *     Request a connection to the system (%n) on TCP port (%p).
X      *
X      stext "~telnet %n %p|"
X      
X      DISCONNE.SCR:
X      *
X      *     Wait for a second of peace and quiet.
X      *
X      waitquiet
X      
X      DROP.SCR:
X      *
X      *     Wait for a second of peace and quiet.
X      *
X      waitquiet
X      *
X      *     Tell terminal server we're done.
X      *
X      stext "~logout|"
X      *
X      delay
X      *
X      waitquiet
X
X
X 
X 
X                        96/11/12
X                        Rudi van Houten
X                        R.vanHouten@cc.ruu.nl
X                        Ac.Comp.Centr.Utrecht
END_OF_FILE
if test 14325 -ne `wc -c <'INSTALL'`; then
    echo shar: \"'INSTALL'\" unpacked with wrong size!
fi
# end of 'INSTALL'
fi
if test -f 'Makefile' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'Makefile'\"
else
echo shar: Extracting \"'Makefile'\" \(8167 characters\)
sed "s/^X//" >'Makefile' <<'END_OF_FILE'
X# SCCS info  Makefile 2.6 96/11/11
X#
X# ========================== COPYRIGHT NOTICE =============================
X# This package srialpop is written by and copyright Rudi van Houten
X# <R.vanHouten@cc.ruu.nl>, it is tested and used now at ACCU (Ac.Comp.
X# Centr.Utrecht, the Netherlands) for several years.
X# 
X# The package consists of four files:
X#     srialpop.c  the C source of the program
X#     Makefile    to build and eventually install the package
X#     README      an old documentation describing the package
X#     INSTALL     a newer document with concise installation instructions
X# 
X# I grant everybody the right to use the package and eventually
X# adapt it to local requirements. Please document your changes in the
X# program source with comments explicitely stating that a modification
X# to the original package has been made. I don't want to be blamed for
X# your errors nor get the praise for your inventions.
X# 
X# Also everybody has the right to bundle this package with other software
X# (e.g. a POP client) on distribution media, but THEN THE UNCHANGED VERSION
X# MUST BE DISTRIBUTED, and no extra fee may be charged for the presence
X# of srialpop in the bundle. If there is a need to modify srialpop for
X# special purposes these modification should be made available as a separate
X# file (e.g. a diff file to be applied with Larry Wall's patch program).
X# 
X# I present this package as is, feeling it can be of use. But no
X# guarantees are given about its proper working or behaviour. It has
X# been used at ACCU for some years now without troubles, so I think it may
X# be bug free. But I cannot be held responsible for any damage or other
X# misery resulting from using srialpop.
X# ===========================================================================
X
X# Makefile to compile srialpop.
X# The "make install" will create an environment for pseudo user ${SRIALPOP}
X# as described in README and INSTALL.
X# That installation will place the program in the directory defined
X# with symbol DEST, default the home directory of the user ${SRIALPOP}.
X# Also a .hushlogin, .cshrc, .login and .profile are created there
X# and a file .forward will be removed. The username ${SRIALPOP} will be
X# placed in /etc/ftpusers to disable ftp access.
X# The user ${SRIALPOP} is asumed to be configured to login with
X# the program srialpop as "loginshell".
X#
X# If that scheme isn't adopted you can use a "make instbin" to simply
X# place the program srialpop in the directory defined by ${HOMEBIN}.
X#
X#########################################################################
X
X#DEST=		/home/srialpop
XDEST=		/usr/people/local/srialpop
XSRIALPOP=	srialpop
XGROUP=		mailusr
XHOMEBIN=	${HOME}/bin
X
X# >>>>>>>>>>>>>>>>>>>>
X# for the meaning of the definitions within DEFS see below
XDEFS= -DLOGGING=LOGBSD43 -DFLOWRTSCTS \
X	-DRMPOPMSG=\"/usr/local/bin/rmpopmsg\"	# in use at ACCU
X
X# Next two lines are probably good definitions on many systems,
X# don't change it here if these do not apply on your system but
X# add a section for your particular system below to override
X# these values.
X# (and mail me these additions please R.vanHouten@cc.ruu.nl.)
XCFLAGS= ${DEFS} -O
XLDFLAGS=
X
X# The symbol DEFS can be defined to influence some properties
X# of the program srialpop, it will be evaluated with CFLAGS.
X# The follwing definitions can be included in DEFS:
X# -DEXTRATTYFLAGS	On some systems it can be needed to enable or
X#			disable some tty-flags I didn't consider.
X#			This can be done by defining the symbol
X#			EXTRATTYFLAGS and writing code in routine
X#			extrattyflags.
X# -DFLOWRTSCTS		Use hardware flow control (RTS/CTS).
X#			This can not be done with old BSD sgtty.h.
X# -DFLOWXONXOFF		use software flow control (XON/XOFF, ^S/^Q).
X# -DLOGGING=ONFILE	Produce logging on the file srialpop.log
X# -DLOGGING-LOGBSD42	Produce logging using the BSD4.2 syslog daemon
X# -DLOGGING=LOGBSD43	Produce logging using the BSD4.3 syslog daemon
X#			If none of these is defined no log is written.
X# -DNO_SMTP             Don't allow access to SMTP service, mail can
X#                       only be sent with the "XTND XMIT" extension to
X#                       POP3.
X#
X# Values that are supplied with the DEFS symbol will override the
X# defaults. coded in the srialpop.c source file
X#
X# For the timeout the default is:
X#    -DTIMEOUT=300
X# if syslog is used. The defaults are:
X#    -DLOGLEVEL=LOG_INFO -DLOGFACILITY=LOG_LOCAL0
X#
X# These values can be redefined in the definition of DEFS above.
X#
X
X# the default set works for SunOS-4.1.3 (and probably 4.1.2 too).
X
X# also IBM's AIX-3.2 works with the default set
X# but define FLOWXONXOFF, not FLOWRTSCTS.
XDEFS= -DLOGGING=LOGBSD43 -DFLOWXONXOFF \
X	-DRMPOPMSG=\"/usr/local/bin/rmpopmsg\"	# in use at ACCU
X
X# use this on Digital's Alpha OSF/1 
X#CFLAGS= ${DEFS} -O3 -std1
X#LDFLAGS=
X
X# use this on Silicon Graphics systems (IRIX-5.3)
X#CFLAGS= ${DEFS} -ansi -O
X#LDFLAGS= -lc_s -s
X
X# use this on Solaris-2.4 (SunOS-5.4)
X#CFLAGS= ${DEFS} -O
X#LDFLAGS= -lsocket -lnsl
X
X# use this on old SysV.3 with a syslogd locally added
X# eg. from John F. Haugh II that looks like BSD-4.3 syslog
X# be aware that these systems generally don't support RTS/CTS
X#CFLAGS= ${DEFS} -O -I/usr/local/include
X#LDFLAGS= -L/usr/local/lib -lsyslog
X
X
X#######################################################################
X#######################################################################
X#######################################################################
X
X# ----------------------------------------------------------------------
X# I don't expect changes will be needed below here
X# ----------------------------------------------------------------------
XSHELL=/bin/sh
XFILES=		README INSTALL Makefile srialpop.c
X
Xsrialpop:	srialpop.o
X		${CC} $? ${LDFLAGS} -o $@
X
Xsrialpop.o:	hdrs.h
X
Xhdrs.h:
X		@( \
X			rm -f hdrs.h; touch hdrs.h; \
X			if [ -f /usr/include/unistd.h ]; then \
X				echo '#include <unistd.h>' >>hdrs.h; \
X			fi; \
X			if [ -f /usr/include/strings.h ]; then \
X				echo '#include <strings.h>' >> hdrs.h; \
X			fi; \
X			if [ -f /usr/include/termios.h ]; then \
X				echo '#define TERM_H TERMIOS' >> hdrs.h; \
X			elif [ -f /usr/include/termio.h ]; then \
X				echo '#define TERM_H TERMIO' >> hdrs.h; \
X			elif [ -f /usr/include/sgtty.h ]; then \
X				echo '#define TERM_H SGTTY' >> hdrs.h; \
X			else \
X				echo 'No termios.h/termio.h/sgtty.h found'; \
X				echo 'Cannot correctly compile srialpop.c'; \
X				exit; \
X			fi; \
X			echo "	File hdrs.h created:"; \
X			echo ""; \
X			cat hdrs.h | while read LINE; \
X				do echo "		$$LINE"; done; \
X			echo "" \
X		)
X
Xinstall:	srialpop
X		@grep "^${SRIALPOP}" /etc/passwd >/dev/null 2>&1 \
X		    || ( \
X			echo ""; \
X			echo "There is no user ${SRIALPOP} in this system!!!"; \
X			echo ".... create one with ${DEST} as home directory"; \
X			exit 1; \
X		      )
X		-mkdir ${DEST}
X		chown root ${DEST}
X		chgrp ${GROUP} ${DEST}
X		chmod 711 ${DEST}
X		cp srialpop ${DEST}
X		strip ${DEST}/srialpop
X		chown root ${DEST}/srialpop
X		chgrp ${GROUP} ${DEST}/srialpop
X		chmod 511 ${DEST}/srialpop
X		touch ${DEST}/.hushlogin
X		echo "exit" > ${DEST}/.login
X		-ln ${DEST}/.login ${DEST}/.cshrc
X		-ln ${DEST}/.login ${DEST}/.profile
X		chown root ${DEST}/.hushlogin ${DEST}/.login
X		chgrp ${GROUP} ${DEST}/.hushlogin ${DEST}/.login
X		chmod 444 ${DEST}/.hushlogin ${DEST}/.login
X		-rm -f ${DEST}/.forward
X		@if [ ! -f /etc/ftpusers ]; then \
X			echo "${SRIALPOP}" > /etc/ftpusers; \
X			chown root /etc/ftpuser; \
X			chmod 600 /etc/ftpusers; \
X			echo /etc/ftpusers created; \
X			ls -l /etc/ftpusers; \
X		else \
X			grep ${SRIALPOP} /etc/ftpusers  >/dev/null 2>&1 \
X			    || ( \
X				echo "${SRIALPOP}" >> /etc/ftpusers; \
X				echo ${SRIALPOP} added to /etc/ftpusers; \
X			       ) \
X		fi
X		@echo ""
X		@echo "If possible, disable the possibility to \"su\" to ${SRIALPOP}"
X		@echo ""
X		@echo Done....
X
Xinstbin:	srialpop ${HOMEBIN}
X		cp srialpop ${HOMEBIN}
X		strip ${HOMEBIN}/srialpop
X		chmod 511 ${HOMEBIN}/srialpop
X
Xclean:
X		rm -f core srialpop *.o hdrs.h srialpop.shar srialpop.tar
X
Xshar:		srialpop.shar
X
Xtar:		srialpop.tar
X
Xsrialpop.shar:	${FILES}
X		shar ${FILES} > srialpop.shar
X
Xsrialpop.tar:	${FILES}
X		tar vfc srialpop.tar ${FILES}
X
X${FILES}:
X		sccs get $@
END_OF_FILE
if test 8167 -ne `wc -c <'Makefile'`; then
    echo shar: \"'Makefile'\" unpacked with wrong size!
fi
# end of 'Makefile'
fi
if test -f 'srialpop.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'srialpop.c'\"
else
echo shar: Extracting \"'srialpop.c'\" \(14329 characters\)
sed "s/^X//" >'srialpop.c' <<'END_OF_FILE'
X/*
X
X    S R I A L P O P  (POP over serial lines)
X
X    Author: Rudi van Houten <R.vanHouten@cc.ruu.nl>
X        Ac.Comp.Centr.Utrecht (Netherlands)
X    With thanks to:
X        Steve Dorner <sdorner@qualcomm.com>
X        Scott Hannahs <sth@slipknot.mit.edu>
X        Mogen Trab Damsgaard <trab@kubism.ku.dk>
X        Richard J. Johnson <johnsonr@Colorado.EDU>
X
X    see the file README for an introduction and hints for installation
X
X========================== COPYRIGHT NOTICE =============================
XThis package srialpop is written by and copyright Rudi van Houten
X<R.vanHouten@cc.ruu.nl>, it is tested and used now at ACCU (Ac.Comp.
XCentr.Utrecht, the Netherlands) for several years.
X
XThe package consists of four files:
X    srialpop.c  the C source of the program
X    Makefile    to build and eventually install the package
X    README      an old documentation describing the package
X    INSTALL     a newer document with concise installation instructions
X
XI grant everybody the right to use the package and eventually
Xadapt it to local requirements. Please document your changes in the
Xprogram source with comments explicitely stating that a modification
Xto the original package has been made. I don't want to be blamed for
Xyour errors nor get the praise for your inventions.
X
XAlso everybody has the right to bundle this package with other software
X(e.g. a POP client) on distribution media, but THEN THE UNCHANGED VERSION
XMUST BE DISTRIBUTED, and no extra fee may be charged for the presence
Xof srialpop in the bundle. If there is a need to modify srialpop for
Xspecial purposes these modification should be made available as a separate
Xfile (e.g. a diff file to be applied with Larry Wall's patch program).
X
XI present this package as is, feeling it can be of use. But no
Xguarantees are given about its proper working or behaviour. It has
Xbeen used at ACCU for some years now without troubles, so I think it may
Xbe bug free. But I cannot be held responsible for any damage or other
Xmisery resulting from using srialpop.
X===========================================================================
X
X*/
Xstatic char sccsid[]= "@(#)srialpop.c	2.3";
X
X/*
X    this is the time to wait (seconds) after a logout command before
X    actually breaking the connection
X*/
X#define LOGOUTGRACE 3
X
X/*
X    define some symbols for the logging facility
X*/
X#define ONFILE 0
X#define LOGBSD42 1
X#define LOGBSD43 2
X/*
X    define the include file for the termio/sgtty structs
X*/
X#define SGTTY   0
X#define TERMIO  1
X#define TERMIOS 2
X
X#include <stdio.h>
X#include "hdrs.h"
X#include <fcntl.h>
X#include <signal.h>
X#include <ctype.h>
X#include <sys/types.h>
X#include <sys/socket.h>
X#include <netinet/in.h>
X#include <netdb.h>
X#include <errno.h>
X#include <string.h>
X#if TERM_H==TERMIOS
X# include <termios.h>
X#elif TERM_H==TERMIO
X# include <termio.h>
X#else
X# include <sgtty.h>
X#endif
X#ifdef __STDC__
X# include <stdarg.h>
X#else
X# include <varargs.h>
X#endif
X#include <time.h>
X#if LOGGING > ONFILE
X# include <syslog.h>
X#endif
X
X#ifndef TIMEOUT
X# define TIMEOUT 300
X#endif
X
X#ifdef LOGGING
X# if LOGGING==ONFILE
X#  define LOG_NOTICE 0
X#  define LOG_INFO 1
X#  undef LOGLEVEL
X#  define LOGLEVEL LOG_INFO
X# else
X#  if LOGGING==LOGBSD43
X#   ifndef LOGFACILITY
X#    define LOGFACILITY LOG_LOCAL0
X#   endif
X#  endif
X#  ifndef LOGLEVEL
X#   define LOGLEVEL LOG_INFO
X#  endif
X# endif
X#endif
X
X#define CRLF "\r\n"
X#define warning(msg) write(2,msg,strlen(msg))
X
X#define iBuflen 512
Xstatic char sBuf[iBuflen];
X
Xstatic short iValidPort[]=
X        {105    /* PH server */
X        ,106    /* password server */
X        ,109    /* POP2 */
X        ,110    /* POP3 */
X#ifndef NO_SMTP
X        ,25     /* SMTP */
X#endif
X        };
X#define iValidPortsCount sizeof(iValidPort)/sizeof(short)
X
X#if TERM_H==TERMIOS
Xstatic struct termios sTermHold, sTermCurr;
X#elif TERM_H==TERMIO
Xstatic struct termio sTermHold, sTermCurr;
X#else
Xstatic struct sgttyb sTermHold, sTermCurr;
X#endif
X
X#if LOGGING==ONFILE
Xstatic char *tMonth[]=
X    {"Jan","Feb","Mar","Apr","May","Jun"
X    ,"Jul","Aug","Sep","Oct","Nov","Dec"
X    };
X#endif
X
X#if TERM_H > SGTTY
X# if defined(sgi) || defined(__sgi)
X#  define CRTSCTS CNEW_RTSCTS
X# elif !defined(CRTSCTS) && defined(FLOWRTSCTS)
X   !! This machine seems unable to set rts/cts flowcontrol
X   !! disable/change that definition in the Makefile in DEFS=
X# endif
X#endif
X
Xextern int errno, sys_nerr;
Xextern char *sys_errlist[];
X
X#ifdef __STDC__
Xstatic void errorexit(const char*, ... );
Xstatic void timetrap(int);
Xstatic void timtrap2(int);
X# ifdef EXTRATTYFLAGS
Xstatic void extrattyflags(void);
X# endif
X# ifdef LOGGING
Xstatic void report(const int,const char*, ...);
X# endif
Xvoid main(void);
X#endif
X
X#ifdef EXTRATTYFLAGS
Xstatic void extrattyflags()
X{
X/*
X * This routine can be enabled by defining EXTRATTYFLAGS
X * in the Makefile.
X * Here code can be placed to add/clear extra flags and
X * attributes in the tty discipline descriptions if you feel
X * the need and don't want to change the main routine.
X */
Xreturn;
X} /* void extrattyflags */
X#endif
X
X#ifdef LOGGING
X# ifdef __STDC__
Xstatic void report(const int level,const char *sFormat, ...)
X{
X# else
Xstatic void report(va_alist) va_dcl
X{
X    int level;
X    char *sFormat;
X# endif
X    char sLogBuf[128];
X    va_list ap;
X# if LOGGING==ONFILE
X    time_t iNow;
X    struct tm *sNow;
X    register FILE *logfile;
X# endif
X# ifdef __STDC__
X    va_start(ap,sFormat);
X# else
X    va_start(ap);
X    level= va_arg(ap,int);
X    sFormat= va_arg(ap,char*);
X# endif
X    vsprintf(sLogBuf,sFormat,ap);
X    va_end(ap);
X# if LOGGING==ONFILE
X    iNow= time(NULL);
X    sNow= localtime(&iNow);
X    if ((logfile= fopen("srialpop.log","a+")) == NULL)
X        warning("Couldn't open logfile, notify system manager\r\n");
X    else
X    {
X        fprintf(logfile,"%2d %s %2d %2d:%2d:%2d [%d]%s: %s\n"
X            ,sNow->tm_mday,tMonth[sNow->tm_mon],sNow->tm_year
X            ,sNow->tm_hour,sNow->tm_min,sNow->tm_sec
X            ,getpid(),level == LOGLEVEL ? "" : " NOTICE",sLogBuf
X            );
X        (void)fclose(logfile);
X    }
X# else
X    (void)syslog(level,"%s",sLogBuf);
X# endif
X} /* void report() */
X#endif
X
X#ifdef __STDC__
Xstatic void errorexit(const char *sFormat, ...)
X{
X#else
Xstatic void errorexit(va_alist) va_dcl
X{
X    char *sFormat;
X#endif
X    char sMsgBuf[128];
X    va_list ap;
X    write(2,CRLF,2);
X#ifdef __STDC__
X    va_start(ap,sFormat);
X#else
X    va_start(ap);
X    sFormat= va_arg(ap,char*);
X#endif
X    vsprintf(sMsgBuf,sFormat,ap);
X    va_end(ap);
X    warning(sMsgBuf);
X    write(2,CRLF,2);
X#ifdef LOGGING
X    report(errno != 0 ? LOG_NOTICE : LOGLEVEL,sMsgBuf);
X#endif
X#if TERM_H==TERMIOS
X    tcsetattr(0,TCSANOW,&sTermHold);
X#elif TERM_H==TERMIO
X    ioctl(0,TCSETAF,&sTermHold);
X#else
X    ioctl(0,TIOCSETP,&sTermHold);
X#endif
X    sleep(1); exit(1);
X} /* errorexit */
X
Xstatic void timetrap(iSign)
Xint iSign;
X{
X    errorexit("Timeout on %d seconds",TIMEOUT);
X} /* timetrap */
X
Xstatic void timtrap2(iSign)
Xint iSign;
X{
X    exit(1);
X} /* timtrap2 */
X
Xvoid main()
X{
Xint iSock, iPort, iChild;
Xregister int i, l;
Xstruct in_addr sInAddr;
Xunion CombineSock
X    {
X        struct sockaddr_in sServer;
X        struct sockaddr addr;
X    } uServer;
Xstruct hostent *psHost, *gethostbyname(), *gethostbyaddr();
Xchar *psCommand, *psName, *psNumber;
X
X#ifdef LOGGING
X# if LOGGING==LOGBSD42
X    openlog("srialpop",LOG_PID);
X# elif LOGGING==LOGBSD43
X    openlog("srialpop",LOG_PID,LOGFACILITY);
X# endif
X#endif
X
X    /* get stty structure sTermHold */
X#if TERM_H==TERMIOS
X(void)tcgetattr(0,&sTermHold);
X#elif TERM_H==TERMIO
Xioctl(0,TCGETA,&sTermHold);
X#else
Xioctl(0,TIOCGETP,&sTermHold);
X#endif
Xmemcpy(&sTermCurr,&sTermHold,sizeof(sTermCurr));
X
X    /* and here prepare the line characteristics */
X
X#if TERM_H > SGTTY
X
X    /* don't translate CR or LF, neither ignore CR */
XsTermCurr.c_iflag  &= ~(ICRNL | INLCR | IGNCR);
X
X# ifndef _POSIX_SOURCE
XsTermCurr.c_iflag &= ~IXANY;
X# endif
X
X# ifdef FLOWXONXOFF
X    /* enable software flow control (XON/XOFF, ^S/^Q) */
XsTermCurr.c_iflag |= (IXON | IXOFF);
X# endif
X
X    /* no output post processing */
XsTermCurr.c_oflag  &= ~OPOST;
X
X# ifdef FLOWRTSCTS
X    /* enable hardware flow control (CTS/RTS) */
XsTermCurr.c_cflag |= CRTSCTS;
X# endif
X
X    /* disable echo, erase/kill processing and special
X     * signal handling (INTR, SUP, QUIT */
XsTermCurr.c_lflag  &= ~(ECHO | ICANON | ISIG );
X
X    /* read will wait endlessly till a character is received,
X     * but a timeout is set with alarm */
XsTermCurr.c_cc[VMIN] = 1;
XsTermCurr.c_cc[VTIME] = 0;
X
X#else
X
X    /* disable echo, CR translation, tab expanding */
XsTermCurr.sg_flags &= ~(ECHO | CRMOD | XTABS);
X    /* set half-cooked mode */
XsTermCurr.sg_flags |= CBREAK;
X    /* get rid of funny old AT&T defaults for erase and kill */
XsTermCurr.sg_erase = 0xff; sTermCurr.sg_kill = 0x15;
X
X# ifdef FLOWRTSCTS
X   !! hardware flow control not supported with sgtty.h
X   !! disable/change that definition in the Makefile in DEFS=
X# endif
X# ifdef FLOWXONXOFF
X    /* set software flow control (XON/XOFF, ^S/^Q) */
XsTermCurr.sg_flags |= TANDEM;
X# endif
X
X#endif
X
X#ifdef EXTRATTYFLAGS
Xextrattyflags();
X#endif
X        /* set line characteristics to NOECHO, NOCRLF etc. */
X#if TERM_H==TERMIOS
Xtcsetattr(0,TCSANOW,&sTermCurr);
X#elif TERM_H==TERMIO
Xioctl(0,TCSETAF,&sTermCurr);
X#else
Xioctl(0,TIOCSETP,&sTermCurr);
X#endif
X
X
X
X/* first set the timeout trap (primitive signal call) */
Xsignal(SIGALRM,timetrap);
X#ifdef LOGGING
Xreport(LOGLEVEL,"srialpop starts processing");
X#endif
X
X/* this is the main loop, it reads the telnet or exit commandline */
Xfor (;;)
X{
X    write(1,"%",1); l= 0;
X    while(alarm(TIMEOUT)
X           ,read(0,&sBuf[l],1) == 1 && sBuf[l] != '\n' && sBuf[l] != '\r'
X         )
X    {
X        alarm(0);
X        write(1,&sBuf[l],1);
X        if (++l >= iBuflen) errorexit("Too long commandline");
X    }
X    if (sBuf[l] == '\n' || sBuf[l] == '\r') sBuf[l]= '\0'; else sBuf[++l]= '\0';
X    if (l == 0) continue;
X    write(1,CRLF,2);
X
X    if (strcmp(sBuf,"logout") == 0
X         || strcmp(sBuf,"exit") == 0
X         || strcmp(sBuf,"quit") == 0
X        )
X        break; /* finished, logout now */
X
X            /* next loop splits the commandline in its constituents */
X    i= 0; psCommand= psName= psNumber= NULL;
X    while (i < l && psNumber == NULL)
X    {
X        while (isspace(sBuf[i])) i++;
X        if (i >= l) break;
X        if (psCommand == NULL) psCommand= &sBuf[i]; /* command found */
X        else
X        if (psName == NULL) psName= &sBuf[i];       /* argument 1 */
X        else psNumber= &sBuf[i];                    /* argument 2 */
X        do { i++; } while (!isspace(sBuf[i]) && i < l);
X        sBuf[i++]= '\0';        /* terminator after last argument */
X    }
X    /* now we have a command (telnet) with two
X       arguments (1=host 2=portnumber) */
X
X    if (strcmp(psCommand,"telnet"))
X        errorexit("Sorry, don't know '%s'\n",psCommand);
X                    /* telnet is the only known command */
X
X    if (psName == NULL || psNumber == NULL)
X        errorexit("Sorry, hostname or portnumber missing\n");
X                        /* and both host and port are required */
X
X    if (l= strlen(psNumber))
X    {
X        for (i= 0; i < l; i++)
X            if (!isdigit(psNumber[i]))
X                errorexit("Portnumber (%s) not numeric\n",psNumber);
X        iPort= atoi(psNumber);
X    }
X    else iPort= 0;
X
X#ifdef LOGGING
X    report(LOGLEVEL,"connect to host %s on port %d",psName,iPort);
X#endif
X
X                        /* check validity of portnumber */
X    for (i=0; iPort != iValidPort[i]; i++)
X        if (i == iValidPortsCount)
X            errorexit("Sorry, %d is not a valid port\n",iPort);
X
X        /*
X           (unsigned long)(-1) = 0xffffffff, returnvalue
X           from inet_addr() if illegal address passed through.
X           I assume then it is a domain name.
X           Thanks to Edwin Kremer (edwin@cs.ruu.nl) for the trick
X        */
X    if ((sInAddr.s_addr= inet_addr(psName)) == 0xffffffff)
X        psHost= gethostbyname(psName);
X    else
X        psHost= gethostbyaddr((char*)&sInAddr,sizeof(struct in_addr),AF_INET);
X    if (psHost == 0)
X        errorexit("Cannot find server %s (host unknown)\n",psName);
X    
X        /* create socket */
X    if ((iSock= socket(AF_INET,SOCK_STREAM,0)) < 0)
X        errorexit("Cannot open IP socket: %s"
X                  , errno > 0 && errno < sys_nerr ? sys_errlist[errno] : ""
X                  );
X
X        /* fill socket structure .....*/
X    uServer.sServer.sin_family= AF_INET;
X    memcpy(&(uServer.sServer.sin_addr),psHost->h_addr,psHost->h_length);
X    uServer.sServer.sin_port= htons(iPort);
X    
X        /*........and connect */
X    if (connect(iSock,&(uServer.addr),sizeof(uServer.addr)) < 0)
X        errorexit("connecting stream socket: %s"
X                  , errno > 0 && errno < sys_nerr ? sys_errlist[errno] : ""
X                  );
X
X        /* now fork a child to copy stdin to socket */
X    iChild= fork();
X    if (iChild < 0) 
X        errorexit("Cannot fork: %s"
X                  , errno > 0 && errno < sys_nerr ? sys_errlist[errno] : ""
X                  );
X    if (iChild == 0)
X    { /* the child copies stdin to the socket */
X        close(1); close(2); /* now close stdout and stderr */
X        signal(SIGALRM,timtrap2); /* reset to even more primitve routine */
X        if (alarm(TIMEOUT), read(0,sBuf,1) == 1)
X        {
X            if (sBuf[0] != '\r' && sBuf[0] != '\n') write(iSock,sBuf,1);
X            while ((alarm(TIMEOUT), l= read(0,sBuf,iBuflen)) > 0)
X                write(iSock,sBuf,l);
X            alarm(0);
X        }
X        close(0); exit(0);
X    } /* if (iChild == 0) */
X    /* no else part, child does exit
X       the parent copies the socket to stdout
X    */
X    while ((alarm(TIMEOUT), l= read(iSock,sBuf,iBuflen)) > 0) write(1,sBuf,l);
X    alarm(0);
X    close(iSock);
X
X    kill(iChild,SIGTERM); /* superfluous */
X#ifdef LOGGING
X    report(LOGLEVEL,"close TCP connection on port %d",iPort);
X#endif
X
X} /* main loop */
X
X#ifdef LOGGING
Xreport(LOGLEVEL,"srialpop session ending normally");
X#endif
X
X        /* reset line characteristics */
X#if TERM_H==TERMIOS
Xtcsetattr(0,TCSANOW,&sTermHold);
X#elif TERM_H==TERMIO
Xioctl(0,TCSETAF,&sTermHold);
X#else
Xioctl(0,TIOCSETP,&sTermHold);
X#endif
X
Xsleep(LOGOUTGRACE); /* wait to satisfy Mac's Hayes Modem Tool */
Xclose(0); close(1); close(2);
X#if LOGGING==LOGBSD42 || LOGGING==LOGBSD43
Xcloselog();
X#endif
Xexit(0);
X} /* main */
END_OF_FILE
if test 14329 -ne `wc -c <'srialpop.c'`; then
    echo shar: \"'srialpop.c'\" unpacked with wrong size!
fi
# end of 'srialpop.c'
fi
echo shar: End of shell archive.
exit 0
