From proff  Mon Jul 29 03:54:15 1996
Received: (proff@localhost) by suburbia.net (8.7.4/Proff-950810) id DAA10697; Mon, 29 Jul 1996 03:54:14 +1000
Received: from tinkertrain.suburbia.net (root@tinkertrain.suburbia.net [203.4.184.254]) by suburbia.net (8.7.4/Proff-950810) with ESMTP id CAA07255; Mon, 29 Jul 1996 02:05:13 +1000
Received: (from puke@localhost) by tinkertrain.suburbia.net (8.7.5/8.6.9) id AAA00929; Mon, 29 Jul 1996 00:31:01 +1000
From: Luke Bowker <puke@tinkertrain.suburbia.net>
Message-Id: <199607281431.AAA00929@tinkertrain.suburbia.net>
Subject: Allowing local commands to run connected to remote hosts
To: ssh@clinet.fi
Date: Mon, 29 Jul 1996 00:30:58 +1000 (EST)
Cc: proff@suburbia.net
X-Mailer: ELM [version 2.4 PL24]
MIME-Version: 1.0
Content-Type: text/plain; charset=US-ASCII
Content-Transfer-Encoding: 7bit
Sender: proff

Here is a patch that adds a -E option to ssh which allows a command to be
run on the local (client) machine with it's stdin/stdout connected to the
remote machine. I use it to do things like:

ssh remote.machine -E pppd -t pppd

which allows me to tunnel a ppp session over an encrypted and compressed
channel.

I didn't write this. The credit for this code goes to Julian Assange
(proff@suburbia.net), but I post it here since he doesn't subscribe
to this list.

Hope others find it useful.

-- 
Luke Bowker, puke@suburbia.net, puke@deakin.edu.au
Suburbia Public Access Network Site Sysadmin

"Don't try to understand. Knowing you, I'm probably wrong" - D. Mustaine


diff --recursive --minimal ssh-1.2.14/Makefile.in sshnew/Makefile.in
166c166
< 	tildexpand.o clientloop.o canohost.o $(COMMON_OBJS)
---
> 	tildexpand.o clientloop.o canohost.o pty.o $(COMMON_OBJS)
diff --recursive --minimal ssh-1.2.14/ssh.c sshnew/ssh.c
166a167
>   fprintf(stderr, "  -E cmd      Run cmd under ssh, with std(in/out) redirected to the remote host.\n");
249a251,264
> #ifndef NOPROF
> int exit_status=0;
> char *execute=NULL;
> 
> reaper()
> {
>   packet_close();
> 
>   /* Exit with the status returned by the program on the remote side. */
>   exit(exit_status);
> }
> #endif
> 
> 
253c268,269
<   int i, opt, optind, type, exit_status, ok, fwd_port, fwd_host_port, authfd;
---
>   int i, opt, optind, type, ok, fwd_port, fwd_host_port, authfd;
> 
333c349
<       if (strchr("eilcpLRo", opt)) /* options with arguments */
---
>       if (strchr("EeilcpLRo", opt)) /* options with arguments */
353a370,374
> #ifndef NOPROFF
>        case 'E':
>          execute = optarg;
>          break;
> #endif
847a869,933
> #ifndef NOPROFF
>    if (execute)
>    {
>        signal(SIGCHLD, reaper);
>        if (tty_flag)
>        {
>                char ttydev[128]="";
>                pid_t child;
>                int ptyfd, ttyfd;
>                tty_flag = 1;
>                if (!pty_allocate(&ptyfd, &ttyfd, ttydev))
>                        exit(1);
>                if (!(child=fork()))
>                {
>                        close(ptyfd);
>                        pty_make_controlling_tty(&ttyfd, ttydev);
>                        if (ttyfd != 0)
>                                dup2(ttyfd, 0);
>                        dup2(ttyfd, 1);
>                        dup2(1, 2);
>                        if (ttyfd!=0)
>                                close(ttyfd);
>                        execlp("sh", "sh",  "-c", execute);
>                        perror("sh");
>                        _exit(1);
>                }
>                if (child==-1)
>                {
>                        perror("fork");
>                        exit(1);
>                }
>                close(ttyfd);
>                dup2(ptyfd, 0);
>                dup2(0, 1);
>          } else
>          {
> 
>                int p1[2], p2[2];
>                pid_t child;
>                pipe(p1);
>                pipe(p2);
>                if (!(child=fork()))
>                {
>                        close(p1[1]);
>                        close(p2[0]);
>                        dup2(p1[0], 0);
>                        dup2(p2[1], 1);
>                        dup2(1, 2);
>                        execlp("sh", "sh",  "-c", execute);
>                        perror("sh");
>                        _exit(1);
>                }
>                if (child==-1)
>                {
>                        perror("fork");
>                        exit(1);
>                }
>                close(p1[0]);
>                close(p2[1]);
>                dup2(p2[0], 0);
>                dup2(p1[1], 1);
>        }
>    }
> #endif
> 
848a935
> 

