This file is indexed.

/usr/sbin/verify-db is in 389-ds-base 1.3.4.9-1.

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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
#!/usr/bin/env perl
#
# BEGIN COPYRIGHT BLOCK
# Copyright (C) 2013 Red Hat, Inc.
# All rights reserved.
#
# License: GPL (version 3 or any later version).
# See LICENSE for details. 
# END COPYRIGHT BLOCK
#

use lib qw(/usr/lib/x86_64-linux-gnu/dirsrv/perl);
use DSUtil;

DSUtil::libpath_add("/usr/lib/x86_64-linux-gnu");
DSUtil::libpath_add("/usr/lib/x86_64-linux-gnu");
$ENV{'PATH'} = "/usr/lib/x86_64-linux-gnu/dirsrv/slapd-$servid:/usr/bin:/usr/bin:/";
$ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
my $custom_dbdir = 0;
my $i = 0;

sub usage
{
  print "Usage: verify-db.pl [-Z serverID] [ -a <fullpath_to_db_dir> ] [-h]\n";
}

# getDbDir checks up to 4 levels of db dirs
# e.g., <server_inst_dir>/db/<backend_instance_dir>/<subdir>
sub getDbDir
{
  (my $here) = @_;
  my @dbdirs = ();

  opendir(DIR0, $here) or die "can't opendir $here : $!";
  while (defined(my $file0 = readdir(DIR0)))
  {
    if ( "$file0" eq "\." || "$file0" eq "\.\." ) 
    {
      ;
    }
    elsif ( "$file0" eq "DBVERSION" )
    {
      $#dbdirs++;
      $dbdirs[$#dbdirs] = $here;
    }
    elsif ( -d $here . "/" . $file0 )
    {
      opendir(DIR1, $here . "/" . $file0) or die "can't opendir $file0 : $!";
      while (defined(my $file1 = readdir(DIR1)))
      {
        if ( "$file1" eq "\." || "$file1" eq "\.\." ) 
        {
          ;
        }
        elsif ( "$file1" eq "DBVERSION" )
        {
          $#dbdirs++;
          $dbdirs[$#dbdirs] = $here . "/" . $file0;
        }
        elsif ( -d $here . "/" . $file0 . "/" . $file1 )
        {
          opendir(DIR2, $here . "/" . $file0 . "/" . $file1) or die "can't opendir $file1 : $!";
          while (defined(my $file2 = readdir(DIR2)))
          {
            if ( "$file2" eq "\." || "$file2" eq "\.\." ) 
            {
              ;
            }
            elsif ("$file2" eq "DBVERSION")
            {
              $#dbdirs++;
              $dbdirs[$#dbdirs] = $here . "/" . $file0 . "/" . $file1;
            }
            elsif ( -d $here . "/" . $file0 . "/" . $file1 . "/" . $file2 )
            {
              opendir(DIR3, $here . "/" . $file0 . "/" . $file1 . "/" . $file2) or die "can't opendir $file1 : $!";
              while (defined(my $file3 = readdir(DIR3)))
              {
                if ( "$file3" eq "\." || "$file3" eq "\.\." ) 
                {
                  ;
                }
                elsif ("$file3" eq "DBVERSION")
                {
                  $#dbdirs++;
                  $dbdirs[$#dbdirs] = $here . "/" . $file0 . "/" . $file1 . "/" . $file2;
                }
              }
              closedir(DIR3);
            }
          }
          closedir(DIR2);
        }
      }
      closedir(DIR1);
    }
  }
  closedir(DIR0);

  return \@dbdirs;
}

sub getLastLogfile
{
  (my $here) = @_;
  my $logfile = "";

  opendir(DIR, $here) or die "can't opendir $here : $!";
  while (defined($file = readdir(DIR)))
  {
    if ($file =~ /log./)
    {
      $logfile = $file;
    }
  }
  closedir(DIR);

  return \$logfile;
}

$NULL = "/dev/null";

while ($i <= $#ARGV) {
  if ( "$ARGV[$i]" eq "-a" ) {  # path to search the db files
    $i++; $startpoint = $ARGV[$i];
  } elsif ( "$ARGV[$i]" eq "-Z" ) {  # server instance identifier
    $i++; $servid = $ARGV[$i];
  } elsif ("$ARGV[$i]" eq "-h") { # help
    &usage; exit(0);
  } else {
    &usage; exit(1);
  }
  $i++;
}

($servid, $notused_configdir) = DSUtil::get_server_id($servid, "/etc/default");

print("*****************************************************************\n");
print("verify-db: This tool should only be run if recovery start fails\n" .
      "and the server is down.  If you run this tool while the server is\n" .
      "running, you may get false reports of corrupted files or other\n" .
      "false errors.\n");
print("*****************************************************************\n");

if ( "$startpoint" eq "" ) {
  $startpoint = "/var/lib/dirsrv/slapd-$servid/db";
} else {
  $custom_dbdir = 1;
}
# get dirs having DBVERSION
my $dbdirs = getDbDir($startpoint);

# Check transaction logs by db_printlog
for (my $i = 0; "$$dbdirs[$i]" ne ""; $i++)
{
  my $logfile = getLastLogfile($$dbdirs[$i]);

  if ( "$$logfile" ne "" )
  {
    # run db_printlog -h <dbdir> for each <dbdir>
    print "Verify log files in $$dbdirs[$i] ... ";
    open(PRINTLOG, "db_printlog -h $$dbdirs[$i] 2>&1 1> $NULL |");
    sleep 1;
    my $haserr = 0;
    while ($l = <PRINTLOG>)
    {
      if ("$l" ne "")
      {
        if ($haserr == 0)
        {
          print "\n";
        }
        print "LOG ERROR: $l";
        $haserr++;
      }
    }
    close(PRINTLOG);
    if ($haserr == 0 && $? == 0)
    {
      print "Good\n";
    }
    else
    {
      print "Log file(s) in $$dbdirs[$i] could be corrupted.\n";
      print "Please delete a log file $$logfile, and try restarting the server.\n";
    }
  }
}

# Check db files by db_verify
print "Verify db files ... ";
if ($custom_dbdir){
    open(DBVERIFY, "/usr/sbin/dbverify -Z $servid -a $startpoint 2>&1 1> $NULL |");
} else {
    open(DBVERIFY, "/usr/sbin/dbverify -Z $servid 2>&1 1> $NULL |");
}
sleep 1;
my $bad_index = 0;
my $bad_id2entry = 0;
my $isfirst = 1;
while ($l = <DBVERIFY>)
{
    if ($isfirst)
    {
        print "\n";
        $isfirst = 0;
    }
    if ("$l" =~ /verify failed/)
    {
        if ("$l" =~ /id2entry.db/)
        {
            $bad_id2entry++;
        }
        else
        {
            $bad_index++;
        }
    }
    print "$l";
}
close(DBVERIFY);

if ($bad_id2entry > 0)
{
    print "\nFound the db was corrupted\n";
    print "Please restore your backup and recover the database.\n";
    exit(1);
}
elsif ($bad_index > 0)
{
    print "\nFound the index file(s) was corrupted\n";
    print "Please run db2index on the corrupted index\n";
    exit(1);
}
else
{
    print "Good\n";
    exit(0);
}