diff options
-rw-r--r-- | Changes | 7 | ||||
-rw-r--r-- | META.json | 6 | ||||
-rw-r--r-- | META.yml | 4 | ||||
-rw-r--r-- | README | 2 | ||||
-rw-r--r-- | lib/Net/OpenSSH.pm | 64 | ||||
-rw-r--r-- | t/quoting.t | 11 |
6 files changed, 73 insertions, 21 deletions
@@ -1,5 +1,12 @@ Revision history for Perl extension Net::OpenSSH. +0.83 Jan 22, 2023 + - Skip quoting test for broken AIX csh shell (bug report by + jrtaisto@gmail.com, #rt133092). + - New FAQ entry about running interactive sessions. + - Add new method "default_ssh_configuration" (feature request + by Diab Jerius, #rt140762). + 0.82 Mar 5, 2022 - Rerelease as stable version @@ -4,7 +4,7 @@ "Salvador Fandino <sfandino@yahoo.com>" ], "dynamic_config" : 1, - "generated_by" : "ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010", + "generated_by" : "ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010", "license" : [ "perl_5" ], @@ -42,6 +42,6 @@ "url" : "https://github.com/salva/p5-Net-OpenSSH" } }, - "version" : "0.82", - "x_serialization_backend" : "JSON::PP version 4.04" + "version" : "0.83", + "x_serialization_backend" : "JSON::PP version 4.06" } @@ -7,7 +7,7 @@ build_requires: configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 1 -generated_by: 'ExtUtils::MakeMaker version 7.44, CPAN::Meta::Converter version 2.150010' +generated_by: 'ExtUtils::MakeMaker version 7.62, CPAN::Meta::Converter version 2.150010' license: perl meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html @@ -21,5 +21,5 @@ requires: Test::More: '0' resources: repository: https://github.com/salva/p5-Net-OpenSSH -version: '0.82' +version: '0.83' x_serialization_backend: 'CPAN::Meta::YAML version 0.018' @@ -27,7 +27,7 @@ This module requires these other modules and libraries: COPYRIGHT AND LICENCE -Copyright (C) 2008-2022 by Salvador Fandino +Copyright (C) 2008-2023 by Salvador Fandino This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10.0 or, diff --git a/lib/Net/OpenSSH.pm b/lib/Net/OpenSSH.pm index 759f69c..c9db163 100644 --- a/lib/Net/OpenSSH.pm +++ b/lib/Net/OpenSSH.pm @@ -1,6 +1,6 @@ package Net::OpenSSH; -our $VERSION = '0.82'; +our $VERSION = '0.83'; use strict; use warnings; @@ -562,21 +562,31 @@ sub _is_secure_path { return 1; } +_sub_options _capture_local_ssh => qw(stderr_to_stdout stderr_discard stderr_fh stderr_file); + +sub _capture_local_ssh { + my $self = shift; + my %opts = (ref $_[0] eq 'HASH' ? %{shift()} : ()); + _croak_bad_options %opts; + my (undef, $out, undef, $pid) = $self->open_ex({ %opts, + _cmd => 'raw', + _no_master_required => 1, + stdout_pipe => 1, + stdin_discard => 1 }, + $self->{_ssh_cmd}, @_); + my ($txt) = $self->_io3($out, undef, undef, undef, 10, 'bytes'); + local $self->{_kill_ssh_on_timeout} = 1; + $self->_waitpid($pid, 10); + return $txt +} + sub _detect_ssh_version { my $self = shift; if (defined $self->{_ssh_version}) { $debug and $debug & 4 and _debug "ssh version given as $self->{_ssh_version}"; } else { - my (undef, $out, undef, $pid) = $self->open_ex({_cmd => 'raw', - _no_master_required => 1, - stdout_pipe => 1, - stdin_discard => 1, - stderr_to_stdout => 1 }, - $self->{_ssh_cmd}, '-V'); - my ($txt) = $self->_io3($out, undef, undef, undef, 10, 'bytes'); - local $self->{_kill_ssh_on_timeout} = 1; - $self->_waitpid($pid, 10); + my $txt = $self->_capture_local_ssh({stderr_to_stdout => 1}, '-V'); if (my ($full, $num) = $txt =~ /^OpenSSH_((\d+\.\d+)\S*)/mi) { $debug and $debug & 4 and _debug "OpenSSH version is $full"; $self->{_ssh_version} = $num; @@ -588,6 +598,11 @@ sub _detect_ssh_version { } } +sub default_ssh_configuration { + my $self = shift; + $self->_capture_local_ssh('-qG', $self->{_host}) +} + sub _make_ssh_call { my $self = shift; my @before = @{shift || []}; @@ -3887,7 +3902,7 @@ passphrase from the user. In asynchronous mode, this method requires the connection to be terminated before it gets called. Afterwards, C<wait_for_master> -should be called repeaptly until the new connection is stablished. +should be called repeatedly until the new connection is established. For instance: my $async = 1; @@ -3991,6 +4006,24 @@ For instance: $ssh->stop; # tells the master to stop accepting requests exit(0); + +=item $ssh->default_ssh_configuration + +Allows one to retrieve the default SSH configuration for the target +host from system files (i.e. C</etc/ssh/ssh_config>) and user files +(C<~/.ssh/config>). + +Under the hood, this method just calls C<ssh -G $host> and returns the +output unprocessed. + +Example: + + my $ssh = Net::OpenSSH->new($host, connect => 0); + my $txt = $ssh->default_ssh_configuration; + my @lines = split /^/m, $txt; + chomp @lines; + my %def_cfg = map split(/\s+/, $_, 2), @lines; + =back =head2 Shell quoting @@ -5072,6 +5105,15 @@ If for whatever reason the methods described above fail, you can always revert to using Expect to talk to the remote C<sudo>. See the C<examples/expect.pl> script from this module distribution. +=item Interactive sessions + +B<Q>: How can I start an interactive remote session? + +B<A>: Just call the C<system> method with an empty argument list: + + my $ssh = Net::OpenSSH->new(...); + $ssh->system; + =back =head1 SEE ALSO diff --git a/t/quoting.t b/t/quoting.t index 09ac46e..ca25f3b 100644 --- a/t/quoting.t +++ b/t/quoting.t @@ -49,7 +49,7 @@ plan tests => @str * @shells; diag "running tests for shells @shells"; for my $shell (@shells) { - # workaround for solaris csh fixing invalid UTF8 sequences. + # workaround for solaris csh fixing invalid UTF8 sequences. local $ENV{LANG} = $alt_lang if $shell eq 'csh' and defined $alt_lang; my $i = 0; @@ -96,10 +96,13 @@ sub try_shell { if ($shell =~ /ksh/) { my $version = `$shell --version 2>&1 </dev/null`; $version =~ /version\s+sh\s+\(AT\&T\s+Research\)/ - and die "skipping tests for broken AT&T ksh shell"; + and die "Skipping tests for broken AT&T ksh shell"; } - else { - $shell eq '!!fish' and die "TODO: add support for fish shell"; + elsif ($shell =~ /csh/ and $^O =~ /^aix/) { + die "Skipping tests for broken AIX csh shell"; + } + elsif ($shell eq '!!fish') { + die "TODO: add support for fish shell"; } }; alarm 0; |