Re: Changing an existing tool to talk over ssh

From: all mail refused (elvis_at_notatla.org.uk)
Date: 03/17/04


Date: 17 Mar 2004 02:50:06 GMT

In article <pGI5c.10198$HK6.96@newssvr23.news.prodigy.com>, Steve Turner wrote:
>When I speak of "ssh-enabled" tools, I'm talking about tools like rsync
>or scp that call ssh under the covers to perform the connection and
>execute a daemon process on behalf of the client. As near as I can
>figure these tools open a pipe (which yields both a read and a write
>handle) connects the read and write handles to the stdin and stdout of a
>forked ssh process, and the handles magically become the mechanism with
>with the client and server speak to each other. If I am correct (in
>spite of my naive understanding of Unix sockets programming, forked
>processes, and duped file handles), can the program I'm looking at be
>made to use only one of those handles for both reading and writing, or
>should I rework the program to use a socket "pair"? Thanks.

If you do the SSH protocol, calculations and all, in your program you're
free to call connect() once and do whatever you want. If you use SSH
as "ssh -N -L 2000:localhost:3000 foreign" you've got much the same.

If you're calling an external ssh program I think you'll want the pair.

#!/usr/bin/perl -w

pipe(RHDOWN,WHDOWN) or die("pipe");
pipe(RHUP,WHUP) or die("pipe");
$pid=fork();
die("fork") unless defined($pid);

if (!$pid) {
    # child
    close(RHUP);
    close(WHDOWN);
    open(STDIN, "<&RHDOWN");
    open(STDOUT, ">&WHUP"); # should do STDERR to
    exec("/usr/local/bin/ssh",
        "SOMEHOST-WITH-PASSWORDLESS-ACCESS", "dc") or die("ssh");
}

# parent
close(RHDOWN);
close(WHUP);

printf(WHDOWN "1\n");
for (1..5) {
    printf(WHDOWN "2*p\n");
}
printf(WHDOWN "quit\n");
close(WHDOWN);
while (<RHUP>) {
    chomp;
    printf("REMOTE DC SAYS :%s:\n", $_);
}

close(RHUP);
waitpid($pid,0);
exit(0);

-- 
Elvis Notargiacomo  master AT barefaced DOT cheek


Relevant Pages

  • Multiple issues with Mac OS X AFP client
    ... Multiple issues with Mac OS X AFP client ... connections to an Apple file server over SSH - a commendable effort to ... .GlobalPreferences.plist (the AFP client does not follow Apple's ...
    (Bugtraq)
  • [Full-Disclosure] Multiple issues with Mac OS X AFP client
    ... Multiple issues with Mac OS X AFP client ... connections to an Apple file server over SSH - a commendable effort to ... .GlobalPreferences.plist (the AFP client does not follow Apple's ...
    (Full-Disclosure)
  • Multiple issues with Mac OS X AFP client
    ... Multiple issues with Mac OS X AFP client ... connections to an Apple file server over SSH - a commendable effort to ... .GlobalPreferences.plist (the AFP client does not follow Apple's ...
    (Full-Disclosure)
  • Re: Explanation of SSH
    ... I am still unclear on how SSH works exactly. ... Client issues SSH command and names server ... "Shopper" says "server sends back its public host and server keys ... Surely there is only one public key it sends ...
    (comp.security.ssh)
  • Re: Remote X over rsh
    ... all I'm doing is running X and ssh. ... the weak machine is the one where on he wishes to display, ... Possibly the "my client" confused the issue; ... just use X without ssh forwarding. ...
    (comp.os.linux.x)