#!/bin/sh
# This is a shell archive (produced by GNU sharutils 4.2.1).
# To extract the files from this archive, save it to some FILE, remove
# everything before the `!/bin/sh' line above, then type `sh FILE'.
#
# Made on 2000-04-24 18:52 EDT by <warlord@rcn.ihtfp.org>.
# Source directory was `/afs/sipb.mit.edu/user/warlord/media/C/secure-ppp/src'.
#
# Existing files will *not* be overwritten unless `-c' is specified.
#
# This shar contains:
# length mode       name
# ------ ---------- ------------------------------------------
#   2763 -r--r--r-- README
#   1151 -r--r--r-- Makefile
#   2480 -r--r--r-- main.c
#    495 -r--r--r-- ip-up
#    428 -r--r--r-- ip-down
#    127 -r--r--r-- .ppprc
#
save_IFS="${IFS}"
IFS="${IFS}:"
gettext_dir=FAILED
locale_dir=FAILED
first_param="$1"
for dir in $PATH
do
  if test "$gettext_dir" = FAILED && test -f $dir/gettext \
     && ($dir/gettext --version >/dev/null 2>&1)
  then
    set `$dir/gettext --version 2>&1`
    if test "$3" = GNU
    then
      gettext_dir=$dir
    fi
  fi
  if test "$locale_dir" = FAILED && test -f $dir/shar \
     && ($dir/shar --print-text-domain-dir >/dev/null 2>&1)
  then
    locale_dir=`$dir/shar --print-text-domain-dir`
  fi
done
IFS="$save_IFS"
if test "$locale_dir" = FAILED || test "$gettext_dir" = FAILED
then
  echo=echo
else
  TEXTDOMAINDIR=$locale_dir
  export TEXTDOMAINDIR
  TEXTDOMAIN=sharutils
  export TEXTDOMAIN
  echo="$gettext_dir/gettext -s"
fi
if touch -am -t 200112312359.59 $$.touch >/dev/null 2>&1 && test ! -f 200112312359.59 -a -f $$.touch; then
  shar_touch='touch -am -t $1$2$3$4$5$6.$7 "$8"'
elif touch -am 123123592001.59 $$.touch >/dev/null 2>&1 && test ! -f 123123592001.59 -a ! -f 123123592001.5 -a -f $$.touch; then
  shar_touch='touch -am $3$4$5$6$1$2.$7 "$8"'
elif touch -am 1231235901 $$.touch >/dev/null 2>&1 && test ! -f 1231235901 -a -f $$.touch; then
  shar_touch='touch -am $3$4$5$6$2 "$8"'
else
  shar_touch=:
  echo
  $echo 'WARNING: not restoring timestamps.  Consider getting and'
  $echo "installing GNU \`touch', distributed in GNU File Utilities..."
  echo
fi
rm -f 200112312359.59 123123592001.59 123123592001.5 1231235901 $$.touch
#
if mkdir _sh03503; then
  $echo 'x -' 'creating lock directory'
else
  $echo 'failed to create lock directory'
  exit 1
fi
# ============= README ==============
if test -f 'README' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'README' '(file already exists)'
else
  $echo 'x -' extracting 'README' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'README' &&
X			PTY Forward Utility
X
The PTYFU utility is a tool that encapsulates PPP within a secured SSH
connection.  First you must configure ptyfu for your host, then compile
the client application, and then install the application.
X
CONFIGURING PTYFU
X
Ptyfu depends upon ssh.  In order to configure, build, and install
ptyfu, you must first have built ssh on your platform.  Unfortunately
a binary of ssh is not sufficient; ptyfu requires an ssh build tree in
order to link against a few of the ssh object files.
X
X
There are a number of configuration files that you need to modify in
order to get PTYFU working for your system.  First, you want to modify
the Makefile.  You should modify all the configuration parameters for
your system.  In particular, you want to set:
X
SSH=/path/to/ssh/build/tree/		<- where SSH is built, for the .o's
X					NOTE: Must end with a slash!
SSH_PROG=/path/to/ssh/application	<- where the SSH app is installed
SSH_USER=p<username>			<- user to login to server
X					NOTE: Agree on this with admin
PPPD_PROG=/path/to/pppd			<- path to the pppd on your client
PPPD_SCRIPTS=/path/to/etc/ppp		<- location of '/etc/ppp' scripts
BORER_HOME=/home/borer			<- location of ptyfu configuration
BIN_DIR=/usr/local/bin			<- localtion to install ptyfu
X
Next, you should modify the .ppprc file.  In particular, you want to
change the IP Address (and possibly netmask) for your PPP host.
Change the IP Address to the one assigned to you by the server
administators. DO NOT RUN USING "207.3.231.63:" -- YOU MUST USE YOUR
OWN CONFIGURATION.
X
X
The rest of the files should be fine, and are configured for tunneling
into Telcordia.
X
X
BUILDING PTYFU
X
Once you've configured the Makefile and have an SSH build tree, you
can build ptyfu.  Just type "make" (or, if you prefer, "make all").
This is the easiest part, and should build the PTYFU application.
X
X
INSTALLING PTYFU
X
You must install a number of files on your system before ptyfu will
work.  Note:  I use RedHat.  The locations of these files are based
upon my experiences using RedHat.  If you are using another Linux
distribution, or if you are using another Unix-based OS, you may need
to change these files somewhat to accomodate your system.
X
Make sure you configured .ppprc appropriately for your system.
X
NOTE: IF YOU ARE USING A SYSTEM OTHER THAN REDHAT, RUNNING "make
install" MAY DO THE WRONG THING.
X
To install ptyfu and the associated configuration files, run
X	make install
X
This will install ip-up and ip-down in your PPP scripts directory as
ip-up.local and ip-down.local.  It will create the BORER_HOME
directory and copy the .ppprc file into it.  Finally, it will install
ptyfu in /usr/local/bin, setuid root.  Unfortunately ptyfu needs to be
run as root in order to run pppd effectively.
X
SHAR_EOF
  (set 20 00 02 14 14 00 56 'README'; eval "$shar_touch") &&
  chmod 0444 'README' ||
  $echo 'restore of' 'README' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'README:' 'MD5 check failed'
8f8fecb43ce06143761c2ac5410c10ee  README
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'README'`"
    test 2763 -eq "$shar_count" ||
    $echo 'README:' 'original size' '2763,' 'current size' "$shar_count!"
  fi
fi
# ============= Makefile ==============
if test -f 'Makefile' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'Makefile' '(file already exists)'
else
  $echo 'x -' extracting 'Makefile' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'Makefile' &&
CC=cc
SHAR=shar
INSTALL=install
X
#SSH= wherever your ssh build tree lives.....
SSH=Athena-TopDir/third/ssh/
X
# Define where to find (or put) various files
SSH_PROG=	/usr/athena/bin/ssh
SSH_USER=	pwarlord
PPPD_PROG=	/usr/sbin/pppd
PPP_SCRIPTS=	/etc/ppp
BORER_HOME=	/home/borer
BIN_DIR=	/usr/local/bin
SETUID=		-DSETUID
X
#########################################################################
# Nothing to see below this line
X
PPPD_RC=	$(BORER_HOME)/.ppprc
PIDFILE=	$(BORER_HOME)/ptyfu.pid
X
CFLAGS+= -DPIDFILE=\"$(PIDFILE)\" -DSSH_PROG=\"$(SSH_PROG)\" \
X	-DSSH_USER=\"$(SSH_USER)\" -DPPPD_PROG=\"$(PPPD_PROG)\" \
X	-DPPPD_RC=\"$(PPPD_RC)\" $(SETUID)
X
OBJS=main.o ${SSH}pty.o ${SSH}log-client.o ${SSH}xmalloc.o
X
all: ptyfu
X
ptyfu: ${OBJS}
X	$(CC) -o ptyfu ${OBJS} -lutil
X
install: ptyfu
X	-mkdir -p $(BORER_HOME)
X	$(INSTALL) .ppprc $(PPPD_RC)
X	-mkdir -p $(BIN_DIR)
X	$(INSTALL) -s -o root -m 4775 ptyfu $(BIN_DIR)/ptyfu
X	$(INSTALL) -m 775 ip-up $(PPP_SCRIPTS)/ip-up.local
X	$(INSTALL) -m 755 ip-down $(PPP_SCRIPTS)/ip-down.local	
X
ptyfu.shar:
X	$(SHAR) README Makefile main.c ip-up ip-down .ppprc >$@
X
${SSH}pty.o:
X	
${SSH}log-client.o:
X	
${SSH}xmalloc.o:
X	
SHAR_EOF
  (set 20 00 03 19 16 45 51 'Makefile'; eval "$shar_touch") &&
  chmod 0444 'Makefile' ||
  $echo 'restore of' 'Makefile' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'Makefile:' 'MD5 check failed'
0cc8c6b92473281a0a36e78535a53960  Makefile
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'Makefile'`"
    test 1151 -eq "$shar_count" ||
    $echo 'Makefile:' 'original size' '1151,' 'current size' "$shar_count!"
  fi
fi
# ============= main.c ==============
if test -f 'main.c' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'main.c' '(file already exists)'
else
  $echo 'x -' extracting 'main.c' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'main.c' &&
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/wait.h> 
X
int ppppid, sshpid;
X
#ifndef PIDFILE
#define PIDFILE "/d2/borer/ptyfu.pid"
#endif
X
#ifndef SSH_PROG
#define SSH_PROG "/usr/pkg/bin/ssh"
#endif
X
#ifndef SSH_USER
#define SSH_USER "Porchard"
#endif
X
#ifndef PPPD_PROG
#define PPPD_PROG "/usr/sbin/pppd"
#endif
X
#ifndef PPPD_RC
#define PPPD_RC "/d2/borer/.ppprc"
#endif
X
void cleanup(int sig) {
X  if (ppppid)
X    kill(ppppid, SIGTERM);
X  sleep(1);
X  if (sshpid)
X    kill(sshpid, SIGTERM);
X  unlink(PIDFILE);
X  exit(1);
}
X
void reaper(int sig) {
X  int status;
X  int deadpid = waitpid(-1, &status, WNOHANG);
X  if (deadpid) {
X    if (deadpid == ppppid) {
X      fprintf(stderr, "pppd died\n");
X      ppppid = 0;
X    }
X    if (deadpid == sshpid) {
X      fprintf(stderr, "ssh died\n");
X      sshpid = 0;
X    }
X  }
}
X
main(int argc, char **argv)
{
X  sigset_t nosig;
X  char ptybuf[64];
X  int pty, tty;
X  char *host;
X  int mypid = getpid();
X  FILE *pidfile;
X
X  if (argc != 2) {
X    fprintf (stderr, "Usage: %s host\n", argv[0]);
X    exit (1);
X  }
X
X  host = argv[1];
X  
X  /* unholy pipefitting: pppd<-ssh->sshd->pppd */
X  signal(SIGCHLD, reaper);
X  signal(SIGINT, cleanup);
X  signal(SIGTERM, cleanup);
X
X  pidfile = fopen(PIDFILE, "w");
X  if (pidfile == NULL) {
X    perror(PIDFILE);
X    exit(1);
X  }
X  fprintf(pidfile, "%d\n", mypid);
X  fclose(pidfile);
X
X  /* grab a pty.. */
X  pty_allocate(&pty, &tty, ptybuf);
X
X  printf("Grabbed %s\n", ptybuf);
X
X  fflush(NULL);
X  ppppid = fork();
X  if (ppppid < 0) {
X    perror("fork");
X    cleanup(0);
X  }
X
X  if (ppppid == 0) {
X    /* child.  start pppd... */
X    dup2(tty, 0);
X    dup2(tty, 1);
X    close(pty);
X    close(tty);
X    sleep(10);
#ifdef SETUID
X    setreuid(0,0);
X    seteuid(0);
X    setuid(0);
#endif    
X    fprintf(stderr, "execing pppd...\n");
X    execlp(PPPD_PROG, "pppd", ptybuf, "passive", "file", PPPD_RC, NULL);
X    fprintf(stderr, "pppd finished?\n");
X    _exit(1);
X  }
X
X  sshpid = fork();
X  if (sshpid < 0) {
X    perror("fork");
X    cleanup(0);
X  }
X
X  if (sshpid == 0) {
X    /* child.  start sshd... */
X    dup2(pty, 0);
X    dup2(pty, 1);
X    close(pty);
X    close(tty);
X
X    fprintf(stderr, "execing ssh...\n");
X    execlp(SSH_PROG, "ssh", host, "-v", "-x", "-l", SSH_USER, NULL);
X    _exit(1);
X  }
X  close(tty);
X  close(pty);
X  while (sshpid || ppppid) {
X    sigemptyset(&nosig);
X    sigsuspend(&nosig);
X    fprintf(stderr, "awake!\n");
X  }
X  cleanup(0);
}
SHAR_EOF
  (set 20 00 03 19 16 45 05 'main.c'; eval "$shar_touch") &&
  chmod 0444 'main.c' ||
  $echo 'restore of' 'main.c' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'main.c:' 'MD5 check failed'
e2562c2a03be32aff12c925332aac2f6  main.c
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'main.c'`"
    test 2480 -eq "$shar_count" ||
    $echo 'main.c:' 'original size' '2480,' 'current size' "$shar_count!"
  fi
fi
# ============= ip-up ==============
if test -f 'ip-up' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'ip-up' '(file already exists)'
else
  $echo 'x -' extracting 'ip-up' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'ip-up' &&
#! /bin/sh
X
umask 22
intf=$1
tty=$2
speed=$3
local=$4
remote=$5
misc=$6
X
case $remote
in
X    207.3.231.*)
X	/sbin/route del -host $remote
X	/sbin/route add -net 192.4.0.0/16 $1
X	/sbin/route add -net 128.96.0.0/16 $1
X
X	# Disable packets between eth0 and ppp
X	/sbin/ipfwadm -I -a deny -P all -D 192.4.0.0/16 -W eth0
X	/sbin/ipfwadm -I -a deny -P all -D 128.96.0.0/16 -W eth0
X	/sbin/ipfwadm -O -a deny -P all -S 192.4.0.0/16 -W eth0
X	/sbin/ipfwadm -O -a deny -P all -S 128.96.0.0/16 -W eth0
X	;;
esac
X
SHAR_EOF
  (set 20 00 04 24 18 51 00 'ip-up'; eval "$shar_touch") &&
  chmod 0444 'ip-up' ||
  $echo 'restore of' 'ip-up' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'ip-up:' 'MD5 check failed'
7c560f661d9093ac2df6a7f8b7a2c656  ip-up
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ip-up'`"
    test 495 -eq "$shar_count" ||
    $echo 'ip-up:' 'original size' '495,' 'current size' "$shar_count!"
  fi
fi
# ============= ip-down ==============
if test -f 'ip-down' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING 'ip-down' '(file already exists)'
else
  $echo 'x -' extracting 'ip-down' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > 'ip-down' &&
#! /bin/sh
intf=$1
tty=$2
speed=$3
local=$4
remote=$5
misc=$6
case $remote
in
X    207.3.231.*)
X	/sbin/route del -net 192.4.0.0 $1
X	/sbin/route del -net 128.96.0.0 $1
X
X	# Clear firewalling
X	/sbin/ipfwadm -I -d deny -P all -D 192.4.0.0/16 -W eth0
X	/sbin/ipfwadm -I -d deny -P all -D 128.96.0.0/16 -W eth0
X	/sbin/ipfwadm -O -d deny -P all -S 192.4.0.0/16 -W eth0
X	/sbin/ipfwadm -O -d deny -P all -S 128.96.0.0/16 -W eth0
X	;;
X
esac
SHAR_EOF
  (set 19 99 05 16 13 01 25 'ip-down'; eval "$shar_touch") &&
  chmod 0444 'ip-down' ||
  $echo 'restore of' 'ip-down' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo 'ip-down:' 'MD5 check failed'
60fb247c394bb105f21fec0bea481fad  ip-down
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < 'ip-down'`"
    test 428 -eq "$shar_count" ||
    $echo 'ip-down:' 'original size' '428,' 'current size' "$shar_count!"
  fi
fi
# ============= .ppprc ==============
if test -f '.ppprc' && test "$first_param" != -c; then
  $echo 'x -' SKIPPING '.ppprc' '(file already exists)'
else
  $echo 'x -' extracting '.ppprc' '(text)'
  sed 's/^X//' << 'SHAR_EOF' > '.ppprc' &&
asyncmap 00000000
X
207.3.231.63:
netmask 255.255.255.0
X
ipparam sludge
mtu 576
noauth
nobsdcomp
nodefaultroute
vj-max-slots 16
SHAR_EOF
  (set 20 00 04 24 18 43 28 '.ppprc'; eval "$shar_touch") &&
  chmod 0444 '.ppprc' ||
  $echo 'restore of' '.ppprc' 'failed'
  if ( md5sum --help 2>&1 | grep 'sage: md5sum \[' ) >/dev/null 2>&1 \
  && ( md5sum --version 2>&1 | grep -v 'textutils 1.12' ) >/dev/null; then
    md5sum -c << SHAR_EOF >/dev/null 2>&1 \
    || $echo '.ppprc:' 'MD5 check failed'
d9c0d9a63377417f25deda9e3fa1cc77  .ppprc
SHAR_EOF
  else
    shar_count="`LC_ALL= LC_CTYPE= LANG= wc -c < '.ppprc'`"
    test 127 -eq "$shar_count" ||
    $echo '.ppprc:' 'original size' '127,' 'current size' "$shar_count!"
  fi
fi
rm -fr _sh03503
exit 0
