This file is indexed.

/usr/share/perl5/MHA/SSHCheck.pm is in mha4mysql-manager 0.53-3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#!/usr/bin/env perl

#  Copyright (C) 2011 DeNA Co.,Ltd.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#   along with this program; if not, write to the Free Software
#  Foundation, Inc.,
#  51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

package MHA::SSHCheck;

use strict;
use warnings FATAL => 'all';

use English qw(-no_match_vars);
use Getopt::Long qw(:config pass_through);
use Carp qw(croak);
use Time::HiRes qw( sleep );
use Log::Dispatch;
use Log::Dispatch::Screen;
use Parallel::ForkManager;
use MHA::Config;
use MHA::ManagerConst;
use MHA::ManagerUtil;
$| = 1;
my $g_global_config_file = $MHA::ManagerConst::DEFAULT_GLOBAL_CONF;
my $g_config_file;

sub do_ssh_connection_check {
  my $servers_ref = shift;
  my $log         = shift;
  my $log_level   = shift;
  my $workdir     = shift;
  my @servers     = @$servers_ref;
  $log->info("Starting SSH connection tests..");
  my $failed = 0;
  my $pm     = new Parallel::ForkManager( $#servers + 1 );

  $pm->run_on_start(
    sub {
      my ( $pid, $target ) = @_;
    }
  );

  $pm->run_on_finish(
    sub {
      my ( $pid, $exit_code, $target ) = @_;
      return if ( $target->{skip_init_ssh_check} );
      my $local_file =
        "$workdir/$target->{ssh_host}_$target->{ssh_port}_ssh_check.log";
      if ($exit_code) {
        $failed = 1;
        $log->error( "\n" . `cat $local_file` );
      }
      else {
        $log->debug( "\n" . `cat $local_file` );
      }
      unlink $local_file;
    }
  );

  foreach my $src (@servers) {
    if ( $pm->start($src) ) {

 # By default, sshd normally accepts only 10 concurrent authentication requests.
 # If we have lots of alive servers, we might reach this limitation so
 # shifting child process invocation time a bit to avoid this problem.
      sleep 0.5;
      next;
    }
    my ( $file, $pplog );
    eval {
      $SIG{INT} = $SIG{HUP} = $SIG{QUIT} = $SIG{TERM} = "DEFAULT";
      $pm->finish(0) if ( $src->{skip_init_ssh_check} );
      $file = "$workdir/$src->{ssh_host}_$src->{ssh_port}_ssh_check.log";
      unlink $file;
      $pplog = Log::Dispatch->new( callbacks => $MHA::ManagerConst::log_fmt );
      $pplog->add(
        Log::Dispatch::File->new(
          name      => 'file',
          filename  => $file,
          min_level => $log_level,
          callbacks => $MHA::ManagerConst::add_timestamp,
          mode      => 'append'
        )
      );
      foreach my $dst (@servers) {
        next if ( $dst->{skip_init_ssh_check} );
        next if ( $src->{id} eq $dst->{id} );
        $pplog->debug(
" Connecting via SSH from $src->{ssh_user}\@$src->{ssh_host}($src->{ssh_ip}:$src->{ssh_port}) to $dst->{ssh_user}\@$dst->{ssh_host}($dst->{ssh_ip}:$dst->{ssh_port}).."
        );
        my $command =
"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $src->{ssh_port} $src->{ssh_user}\@$src->{ssh_ip} \"ssh $MHA::ManagerConst::SSH_OPT_CHECK -p $dst->{ssh_port} $dst->{ssh_user}\@$dst->{ssh_ip} exit 0\"";
        my ( $high, $low ) = MHA::ManagerUtil::exec_system( $command, $file );
        if ( $high != 0 || $low != 0 ) {
          $pplog->error(
"SSH connection from $src->{ssh_user}\@$src->{ssh_host}($src->{ssh_ip}:$src->{ssh_port}) to $dst->{ssh_user}\@$dst->{ssh_host}($dst->{ssh_ip}:$dst->{ssh_port}) failed!"
          );
          $pm->finish(1);
        }
        $pplog->debug("  ok.");
      }
      $pm->finish(0);
    };
    if ($@) {
      $pplog->error($@) if ($pplog);
      undef $@;
      $pm->finish(1);
    }
  }
  $pm->wait_all_children;
  croak "SSH Configuration Check Failed!\n" if ($failed);

  $log->info("All SSH connection tests passed successfully.");
}

sub main {
  @ARGV = @_;
  GetOptions(
    'global_conf=s' => \$g_global_config_file,
    'conf=s'        => \$g_config_file,
  );
  unless ($g_config_file) {
    print "--conf=<server_config_file> must be set.\n";
    return 1;
  }
  my $log  = MHA::ManagerUtil::init_log();
  my $conf = new MHA::Config(
    logger     => $log,
    globalfile => $g_global_config_file,
    file       => $g_config_file
  );
  my @servers_config = $conf->read_config();
  $log = MHA::ManagerUtil::init_log( undef, "debug" );
  return do_ssh_connection_check( \@servers_config, $log, "debug", "/tmp" );
}

1;