#!/usr/bin/perl -- # Perl wrapper around rsh/remsh to export DISPLAY and run an xterm # Usage: # remoteshell hostname [-l remoteuser] $rsh= 'ssh'; $usesh= ''; $rsh= shift if $ARGV[0] =~ s/^-r//; $usesh= shift if $ARGV[0] =~ s/^-s//; ($remotehost= shift) || die "need hostname\n"; $remotehost= (gethostbyname($remotehost))[0] || $remotehost; if ($ARGV[0] eq '-l') { shift; ($remoteuser= shift) || die "need username after -l\n"; $remoteuser= "-l $remoteuser"; } elsif (open(H,"$ENV{'HOME'}/.rhosts")) { while () { m/^(\S+)\s+(\S+)\s*$/ || next; if (&canon($1) eq &canon($remotehost)) { $remoteuser= "-l $2"; last; } } } $_= $ENV{'DISPLAY'}; m/:/ || die "\$DISPLAY variable format `$_' bad"; $ENV{'DISPLAY'}= &canon($`).':'.$'; sub canon { local ($h) = @_; local ($v,@h,@v); chomp($h= `hostname`) unless length($h); @h= gethostbyname($h); return $h unless @h; @v= gethostbyaddr($h[4],$h[2]); $v= $v[0]; # unless ($v =~ m/\./) { # $v .= '.'; # $v .= `domainname`; # $v =~ s/\n$//; # } return $v; } open(U,"|$rsh $remotehost $remoteuser perl") || die "failed to run $rsh: $!"; print U <<'END' ; $_= ; chop; @ar= split(/\0/,$_) if length($_); $_= ; chop; $ENV{'DISPLAY'}= $_; $_= ; chop; $usesh= $_; $host= ; chop($host); $pcmd= '. .configs/setenvir; echo ok $PATH'; $pout= `$pcmd`; $pout =~ m/^ok (\S+)\n$/ || die "pcmd gave `$pout'"; $ENV{'PATH'}= $1; open(X,"|xauth nmerge -"); while () { print X; } close(X); $? && die "xauth gave code $?"; defined($c= fork) || die "fork: $!"; exit 0 if $c; close(STDIN); close(STDOUT); open(STDIN,">.remoteshell-errors") || die "append .remoteshell-errors: $!"; chmod(0600,".remoteshell-errors"); close(STDERR); open(STDERR,">&STDOUT"); if ($usesh eq '') { exec('close3onwards','xterm','-T',$host,@ar,'-e','.configs/rxprofile'); } else { exec('close3onwards',$usesh,'-xc','. .configs/setenvir; exec "$@"','-',@ar); } print STDERR "close3onwards: $!\n"; exit 1; __END__ END print U join("\0",@ARGV),"\n"; print U $ENV{'DISPLAY'},"\n"; print U $usesh,"\n"; print U $remotehost,"\n"; print U `xauth nextract - $ENV{'DISPLAY'}`; close(U); $? && die "remoteshell $rsh gave code $?"; exit 0;