[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH RFC 1/4] osstest: add routine to execute ssh with password



This is needed when bootstrapping FreeBSD, since the installer has ssh
enabled with the root password set to 'root' by default.

Signed-off-by: Roger Pau Monnà <roger.pau@xxxxxxxxxx>
Cc: Ian Jackson <Ian.Jackson@xxxxxxxxxxxxx>
---
 Osstest/TestSupport.pm |   39 ++++++++++++++++++++++++++++++++++-----
 1 files changed, 34 insertions(+), 5 deletions(-)

diff --git a/Osstest/TestSupport.pm b/Osstest/TestSupport.pm
index fea54d5..57b8a82 100644
--- a/Osstest/TestSupport.pm
+++ b/Osstest/TestSupport.pm
@@ -60,6 +60,7 @@ BEGIN {
                       target_install_packages target_install_packages_norec
                       target_jobdir target_extract_jobdistpath_subdir
                       target_extract_jobdistpath target_guest_lv_name
+                      target_cmd_root_with_password
 
                       poll_loop tcpconnect await_tcp
                       contents_make_cpio file_simple_write_contents
@@ -313,12 +314,11 @@ END
 #---------- running commands eg on targets ----------
 
 sub cmd {
-    my ($timeout,$stdout,@cmd) = @_;
+    my ($timeout,$child_sub,@cmd) = @_;
     my $child= fork;  die $! unless defined $child;
     if (!$child) {
-        if (defined $stdout) {
-            open STDOUT, '>&', $stdout
-                or die "STDOUT $stdout $cmd[0] $!";
+        if (defined $child_sub) {
+            $child_sub->();
         }
         exec @cmd;
         die "$cmd[0]: $!";
@@ -573,9 +573,38 @@ sub tcmd { # $tcmd will be put between '' but not escaped
 sub target_cmd ($$;$) { tcmd(undef,'osstest',@_); }
 sub target_cmd_root ($$;$) { tcmd(undef,'root',@_); }
 
+sub target_cmd_root_with_password {
+    my ($ho,$tcmd,$timeout,$password) = @_;
+
+    open(my $temp_fh, '>', "tmp/t.ssh-password-helper.$flight.$job")
+      or die "Cannot open tmp/t.ssh-password-helper.$flight.$job: $!";
+    print $temp_fh "#!/bin/sh\n\necho \"$password\"\n";
+    chmod 0755, $temp_fh;
+    close $temp_fh;
+
+    my $child_sub = sub {
+                           $ENV{DISPLAY} = ":0";
+                           $ENV{SSH_ASKPASS} = 
"tmp/t.ssh-password-helper.$flight.$job";
+                           setsid or die "Can't start a new session: $!";
+                        };
+
+    my $ssh_opts = [qw(-o BatchMode=no
+                       -o PasswordAuthentication=yes
+                       -o ChallengeResponseAuthentication=yes),
+                    @{ sshopts() }];
+
+    tcmdex($timeout,$child_sub,
+           'ssh', $ssh_opts,
+           sshuho("root",$ho), $tcmd);
+
+    unlink $temp_fh;
+}
+
 sub tcmdout {
     my $stdout= IO::File::new_tmpfile();
-    tcmd($stdout,@_);
+    my $stdout_sub = sub { open STDOUT, '>&', $stdout
+                              or die "STDOUT $stdout $!"; };
+    tcmd($stdout_sub,@_);
     $stdout->seek(0,0) or die "$stdout $!";
     my $r;
     { local ($/) = undef;
-- 
1.7.7.5 (Apple Git-26)


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.