summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHiroyuki Sato <hiroysato@gmail.com>2014-04-22 23:48:30 +0900
committerDaniil Baturin <daniil@baturin.org>2014-04-27 00:20:27 +0200
commit79c9cb87aa3e44ad24275a05e38c14f7aaa71cce (patch)
tree93e07a607e80a6e031c5ec7f580b40da9754bb43
parentefe48326de18352648bc73c015e0543d7901a7a8 (diff)
downloadvyatta-cfg-79c9cb87aa3e44ad24275a05e38c14f7aaa71cce.tar.gz
vyatta-cfg-79c9cb87aa3e44ad24275a05e38c14f7aaa71cce.zip
Bug #180 save config using scp fails.
-rwxr-xr-xscripts/vyatta-save-config.pl45
1 files changed, 27 insertions, 18 deletions
diff --git a/scripts/vyatta-save-config.pl b/scripts/vyatta-save-config.pl
index 8695d53..b397195 100755
--- a/scripts/vyatta-save-config.pl
+++ b/scripts/vyatta-save-config.pl
@@ -121,27 +121,36 @@ fsync $save;
close $save;
if ($mode eq 'url') {
- my $rc = system("curl -# -T $url_tmp_file $save_file");
- if ($proto eq 'scp' && ($rc >> 8) == 51){
+
+ my $rc = 0;
+ if ($proto eq 'scp' ){
$save_file =~ m/scp:\/\/(.*?)\//;
my $host = $1;
- if ($host =~ m/.*@(.*)/) {
- $host = $1;
- }
- my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
- print "The authenticity of host '$host' can't be established.\n";
- my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
- chomp $fingerprint;
- print "RSA key fingerprint is $fingerprint.\n";
- if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
- mkdir "~/.ssh/";
- open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts")
- or die "Cannot open known_hosts: $!";
- print $known_hosts "$rsa_key\n";
- close($known_hosts);
- $rc = system("curl -# -T $url_tmp_file $save_file");
- print "\n";
+ my $user = getpwuid($<);
+ if ($host =~ m/(.*)@(.*)/) {
+ $user = $1;
+ $host = $2;
}
+
+ $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
+ if( $rc >> 8 == 51 ){
+ my $rsa_key = `ssh-keyscan -t rsa $host 2>/dev/null`;
+ print "The authenticity of host '$host' can't be established.\n";
+ my $fingerprint = `ssh-keygen -lf /dev/stdin <<< \"$rsa_key\" | awk {' print \$2 '}`;
+ chomp $fingerprint;
+ print "RSA key fingerprint is $fingerprint.\n";
+ if (prompt("Are you sure you want to continue connecting (yes/no) [Yes]? ", -tynd=>"y")) {
+ mkdir "$ENV{HOME}/.ssh/",0700 unless -d "$ENV{HOME}/.ssh";
+ open(my $known_hosts, ">>", "$ENV{HOME}/.ssh/known_hosts")
+ or die "Cannot open known_hosts: $!";
+ print $known_hosts "$rsa_key\n";
+ close($known_hosts);
+ $rc = system("curl -u $user -# -T $url_tmp_file $save_file");
+ print "\n";
+ }
+ }
+ } else {
+ $rc = system("curl -# -T $url_tmp_file $save_file");
}
system("rm -f $url_tmp_file");
if ($rc) {