This file is indexed.

/usr/share/cluster/fence_scsi_check.pl is in fence-agents 3.1.5-2ubuntu2.

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

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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
#!/usr/bin/perl

use POSIX;

################################################################################

my $dev_file = "/var/run/cluster/fence_scsi.dev";
my $key_file = "/var/run/cluster/fence_scsi.key";

################################################################################

sub log_debug ($)
{
    my $time = strftime ("%b %e %T", localtime);
    my $msg = shift;

    print STDOUT "$time [$0] debug: $msg\n" if ($verbose);

    return;
}

sub log_error ($)
{
    my $time = strftime ("%b %e %T", localtime);
    my $msg = shift;

    print STDERR "$time [$0] error: $msg\n";

    return;
}

sub do_reset ($)
{
    my $dev = shift;

    my $cmd = "sg_turs $dev";
    my @out = qx { $cmd 2> /dev/null };

    return;
}

sub get_registration_keys ($)
{
    my $dev = shift;
    my @keys = ();

    do_reset ($dev);

    my $cmd = "sg_persist -n -i -k -d $dev";
    my @out = qx { $cmd 2> /dev/null };

    if ($?>>8 != 0) {
	log_error ("$cmd");
	exit (0);
    }

    foreach (@out) {
	chomp;
	if (s/^\s+0x//i) {
	    push (@keys, $_);
	}
    }

    return (@keys);
}

sub get_reservation_keys ($)
{
    my $dev = shift;
    my @keys = ();

    do_reset ($dev);

    my $cmd = "sg_persist -n -i -r -d $dev";
    my @out = qx { $cmd 2> /dev/null };

    if ($?>>8 != 0) {
	log_error ("$cmd");
	exit (0);
    }

    foreach (@out) {
	chomp;
	if (s/^\s+key=0x//i) {
	    push (@keys, $_);
	}
    }

    return (@keys);
}

sub get_verbose ()
{
    open (\*FILE, "</etc/sysconfig/watchdog") or return;
    chomp (my @opt = <FILE>);
    close (FILE);

    foreach (@opt) {
	next if (/^#/);
	next unless ($_);

	if (/^verbose=yes$/i) {
	    return (1);
	}
    }

    return (0);
}

sub key_read ()
{
    open (\*FILE, "<$key_file") or exit (0);
    chomp (my $key = <FILE>);
    close (FILE);

    return ($key);
}

sub dev_read ()
{
    open (\*FILE, "<$dev_file") or exit (0);
    chomp (my @dev = <FILE>);
    close (FILE);

    return (@dev);
}

################################################################################

if ($ARGV[0] =~ /^repair$/i) {
    exit ($ARGV[1]);
}

if (-e "/etc/sysconfig/watchdog") {
    $verbose = get_verbose ();
}

if (! -e $dev_file) {
    log_debug ("$dev_file does not exit");
    exit (0);
} elsif (-z $dev_file) {
    log_debug ("$dev_file is empty");
    exit (0);
}

if (! -e $key_file) {
    log_debug ("$key_file does not exist");
    exit (0);
} elsif (-z $key_file) {
    log_debug ("$key_file is empty");
    exit (0);
}

my $key = key_read ();
my @dev = dev_read ();

foreach (@dev) {
    my @keys = grep { /^$key$/i } get_registration_keys ($_);

    if (scalar (@keys) != 0) {
	log_debug ("key $key registered with device $_");
	exit (0);
    } else {
	log_debug ("key $key not registered with device $_");
    }
}

log_debug ("key $key not registered with any devices");

exit (2);