anndl: Fixed a couple of bugs.
[utils.git] / rsc
diff --git a/rsc b/rsc
index a84668d..74be3fd 100755 (executable)
--- a/rsc
+++ b/rsc
@@ -1,13 +1,20 @@
 #!/usr/bin/perl
 
+use MIME::Base64;
+
 if(@ARGV < 1) {
     print STDERR "usage: rsc HOST CMD ARG...\n";
     exit 1;
 }
 
 if($ARGV[0] eq "-s") {
+    if(!defined($ARGV[1])) {
+       print STDERR "rsc: server side needs arguments\n";
+       exit 1
+    }
+    $arg = decode_base64($ARGV[1]);
     $c = "";
-    while(<STDIN>) {
+    for (split /\n/, $arg) {
        chomp;
        s/\\(.)/$1/g;
        $c .= $_;
@@ -25,17 +32,17 @@ if($ARGV[0] eq "-s") {
     }
 } else {
     $host = shift @ARGV;
-    $pid = open SSH, "|-";
-    if($pid == 0) {
-       exec "ssh", "$host", "rsc", "-s";
-       die "$!";
-    }
+    $arg = "";
     for (@ARGV) {
        s/([\\\n])/\\$1/g;
-       print SSH "$_\n";
+       $arg .= "$_\n";
     }
-    close SSH;
-    waitpid $pid, 0;
+    $ea = encode_base64($arg);
+    $ea =~ s/\n//g;
+    if(-t STDIN) {
+       push @sshopts, "-t";
+    }
+    push @sshopts, "-q";
+    exec "ssh", @sshopts, "$host", "rsc", "-s", $ea;
+    die "$!";
 }
-
-