Skip to content

Commit

Permalink
Merge pull request jimsalterjrs#374 from aerusso/pulls/syncoid-dont-r…
Browse files Browse the repository at this point in the history
…equire-user

Do not require user to be specified for syncoid
  • Loading branch information
jimsalterjrs authored Nov 1, 2020
2 parents 58263cc + f397687 commit 345e7e5
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions syncoid
Original file line number Diff line number Diff line change
Expand Up @@ -1425,20 +1425,53 @@ sub targetexists {
sub getssh {
my $fs = shift;

my $rhost;
my $rhost = "";
my $isroot;
my $socket;
my $remoteuser = "";

# if we got passed something with an @ in it, we assume it's an ssh connection, eg root@myotherbox
if ($fs =~ /\@/) {
$rhost = $fs;
$fs =~ s/^\S*\@\S*://;
$fs =~ s/^[^\@:]*\@[^\@:]*://;
$rhost =~ s/:\Q$fs\E$//;
my $remoteuser = $rhost;
$remoteuser =~ s/\@.*$//;
$remoteuser = $rhost;
$remoteuser =~ s/\@.*$//;
# do not require a username to be specified
$rhost =~ s/^@//;
} elsif ($fs =~ m{^[^/]*:}) {
# if we got passed something with an : in it, BEFORE any forward slash
# (i.e., not in a dataset name) it MAY be an ssh connection
# but we need to check if there is a pool with that name
my $pool = $fs;
$pool =~ s%/.*$%%;
my ($pools, $error, $exit) = capture {
system("$zfscmd list -d0 -H -oname");
};
$rhost = $fs;
if ($exit != 0) {
warn "Unable to enumerate pools (is zfs available?)";
} else {
foreach (split(/\n/,$pools)) {
if ($_ eq $pool) {
# there's a pool with this name.
$rhost = "";
last;
}
}
}
if ($rhost ne "") {
# there's no pool that might conflict with this
$rhost =~ s/:.*$//;
$fs =~ s/\Q$rhost\E://;
}
}

if ($rhost ne "") {
if ($remoteuser eq 'root' || $args{'no-privilege-elevation'}) { $isroot = 1; } else { $isroot = 0; }
# now we need to establish a persistent master SSH connection
$socket = "/tmp/syncoid-$remoteuser-$rhost-" . time();
$socket = "/tmp/syncoid-$rhost-" . time();

open FH, "$sshcmd -M -S $socket -o ControlPersist=1m $args{'sshport'} $rhost exit |";
close FH;

Expand Down Expand Up @@ -1887,9 +1920,9 @@ syncoid - ZFS snapshot replication tool
=head1 SYNOPSIS
syncoid [options]... SOURCE TARGET
or syncoid [options]... SOURCE USER@HOST:TARGET
or syncoid [options]... USER@HOST:SOURCE TARGET
or syncoid [options]... USER@HOST:SOURCE USER@HOST:TARGET
or syncoid [options]... SOURCE [[USER]@]HOST:TARGET
or syncoid [options]... [[USER]@]HOST:SOURCE TARGET
or syncoid [options]... [[USER]@]HOST:SOURCE [[USER]@]HOST:TARGET
SOURCE Source ZFS dataset. Can be either local or remote
TARGET Target ZFS dataset. Can be either local or remote
Expand Down

0 comments on commit 345e7e5

Please sign in to comment.