amoralej / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 years ago
Clone

Blame SOURCES/0034-Ticket-48215-verify_db.pl-doesn-t-verify-DB-specifie.patch

a2f18f
From a117d87aac507e4002429e5f7aebe61a867da06d Mon Sep 17 00:00:00 2001
a2f18f
From: Mark Reynolds <mreynolds@redhat.com>
a2f18f
Date: Wed, 5 Aug 2015 16:31:49 -0400
a2f18f
Subject: [PATCH 34/39] Ticket 48215 - verify_db.pl doesn't verify DB specified
a2f18f
 by -a option
a2f18f
a2f18f
Bug Description:  verify_db.pl -a only uses the db location for
a2f18f
                  checking the transaction logs, because it ends up
a2f18f
                  calling "nsslapd dbverify" which only checks the
a2f18f
                  db files in the server configuration.
a2f18f
a2f18f
Fix Description:  Allow a new argument to be passed to "nsslapd dbverify"
a2f18f
                  that specifies the db parent directory.
a2f18f
a2f18f
https://fedorahosted.org/389/ticket/48215
a2f18f
a2f18f
Reviewed by: nhosoi(Thanks!)
a2f18f
a2f18f
(cherry picked from commit 27fadb75ec1f3b252028ce715cd7fa16da1f6525)
a2f18f
(cherry picked from commit 210071c682751897099e8eb138e5db1e47ac2bae)
a2f18f
---
a2f18f
 ldap/admin/src/scripts/dbverify.in      |  3 ++-
a2f18f
 ldap/admin/src/scripts/verify-db.pl.in  | 17 +++++++++--------
a2f18f
 ldap/servers/slapd/back-ldbm/dbverify.c | 13 +++++++++++++
a2f18f
 ldap/servers/slapd/main.c               | 18 +++++++++++++-----
a2f18f
 ldap/servers/slapd/pblock.c             | 12 +++++++++++-
a2f18f
 ldap/servers/slapd/slap.h               |  2 ++
a2f18f
 ldap/servers/slapd/slapi-plugin.h       |  3 +++
a2f18f
 man/man8/dbverify.8                     |  3 +++
a2f18f
 8 files changed, 56 insertions(+), 15 deletions(-)
a2f18f
a2f18f
diff --git a/ldap/admin/src/scripts/dbverify.in b/ldap/admin/src/scripts/dbverify.in
a2f18f
index 6306a07..778a9ba 100755
a2f18f
--- a/ldap/admin/src/scripts/dbverify.in
a2f18f
+++ b/ldap/admin/src/scripts/dbverify.in
a2f18f
@@ -26,7 +26,7 @@ usage()
a2f18f
 }
a2f18f
 
a2f18f
 display_version="no"
a2f18f
-while getopts "Z:n:hVvfd:n:D:" flag
a2f18f
+while getopts "Z:n:hVvfd:n:D:a:" flag
a2f18f
 do
a2f18f
     case $flag in
a2f18f
         h) usage
a2f18f
@@ -39,6 +39,7 @@ do
a2f18f
            display_version="yes";;
a2f18f
         f) args=$args" -f";;
a2f18f
         D) args=$args" -D $OPTARG";;
a2f18f
+        a) args=$args" -a $OPTARG";;
a2f18f
         ?) usage
a2f18f
            exit 1;;
a2f18f
     esac
a2f18f
diff --git a/ldap/admin/src/scripts/verify-db.pl.in b/ldap/admin/src/scripts/verify-db.pl.in
a2f18f
index ae56a16..d481ecb 100644
a2f18f
--- a/ldap/admin/src/scripts/verify-db.pl.in
a2f18f
+++ b/ldap/admin/src/scripts/verify-db.pl.in
a2f18f
@@ -16,7 +16,7 @@ DSUtil::libpath_add("@db_libdir@");
a2f18f
 DSUtil::libpath_add("@libdir@");
a2f18f
 $ENV{'PATH'} = "@libdir@/@package_name@/slapd-$servid:@db_bindir@:/usr/bin:/";
a2f18f
 $ENV{'SHLIB_PATH'} = "$ENV{'LD_LIBRARY_PATH'}";
a2f18f
-
a2f18f
+my $custom_dbdir = 0;
a2f18f
 my $i = 0;
a2f18f
 
a2f18f
 sub usage
a2f18f
@@ -118,12 +118,7 @@ sub getLastLogfile
a2f18f
   return \$logfile;
a2f18f
 }
a2f18f
 
a2f18f
-$isWin = -d '\\';
a2f18f
-if ($isWin) {
a2f18f
-  $NULL = "nul";
a2f18f
-} else {
a2f18f
-  $NULL = "/dev/null";
a2f18f
-}
a2f18f
+$NULL = "/dev/null";
a2f18f
 
a2f18f
 while ($i <= $#ARGV) {
a2f18f
   if ( "$ARGV[$i]" eq "-a" ) {  # path to search the db files
a2f18f
@@ -149,6 +144,8 @@ print("*****************************************************************\n");
a2f18f
 
a2f18f
 if ( "$startpoint" eq "" ) {
a2f18f
   $startpoint = "@localstatedir@/lib/@PACKAGE_NAME@/slapd-$servid/db";
a2f18f
+} else {
a2f18f
+  $custom_dbdir = 1;
a2f18f
 }
a2f18f
 # get dirs having DBVERSION
a2f18f
 my $dbdirs = getDbDir($startpoint);
a2f18f
@@ -192,7 +189,11 @@ for (my $i = 0; "$$dbdirs[$i]" ne ""; $i++)
a2f18f
 
a2f18f
 # Check db files by db_verify
a2f18f
 print "Verify db files ... ";
a2f18f
-open(DBVERIFY, "@sbindir@/dbverify -Z $servid 2>&1 1> $NULL |");
a2f18f
+if ($custom_dbdir){
a2f18f
+    open(DBVERIFY, "@sbindir@/dbverify -Z $servid -a $startpoint 2>&1 1> $NULL |");
a2f18f
+} else {
a2f18f
+    open(DBVERIFY, "@sbindir@/dbverify -Z $servid 2>&1 1> $NULL |");
a2f18f
+}
a2f18f
 sleep 1;
a2f18f
 my $bad_index = 0;
a2f18f
 my $bad_id2entry = 0;
a2f18f
diff --git a/ldap/servers/slapd/back-ldbm/dbverify.c b/ldap/servers/slapd/back-ldbm/dbverify.c
a2f18f
index 85ee7a0..315ef93 100644
a2f18f
--- a/ldap/servers/slapd/back-ldbm/dbverify.c
a2f18f
+++ b/ldap/servers/slapd/back-ldbm/dbverify.c
a2f18f
@@ -186,13 +186,16 @@ ldbm_back_dbverify( Slapi_PBlock *pb )
a2f18f
     int rval              = 1;
a2f18f
     int rval_main         = 0;
a2f18f
     char **instance_names = NULL;
a2f18f
+    char *dbdir           = NULL;
a2f18f
 
a2f18f
     slapi_log_error(SLAPI_LOG_TRACE, "verify DB", "Verifying db files...\n");
a2f18f
     slapi_pblock_get(pb, SLAPI_BACKEND_INSTANCE_NAME, &instance_names);
a2f18f
     slapi_pblock_get(pb, SLAPI_SEQ_TYPE, &verbose);
a2f18f
     slapi_pblock_get(pb, SLAPI_PLUGIN_PRIVATE, &li;;
a2f18f
+    slapi_pblock_get(pb, SLAPI_DBVERIFY_DBDIR, &dbdir);
a2f18f
     ldbm_config_load_dse_info(li);
a2f18f
     ldbm_config_internal_set(li, CONFIG_DB_TRANSACTION_LOGGING, "off");
a2f18f
+
a2f18f
     /* no write needed; choose EXPORT MODE */
a2f18f
     if (0 != dblayer_start(li, DBLAYER_EXPORT_MODE))
a2f18f
     {
a2f18f
@@ -211,6 +214,11 @@ ldbm_back_dbverify( Slapi_PBlock *pb )
a2f18f
             inst = ldbm_instance_find_by_name(li, *inp);
a2f18f
             if (inst)
a2f18f
             {
a2f18f
+                if (dbdir){
a2f18f
+                    /* verifying backup */
a2f18f
+                    slapi_ch_free_string(&inst->inst_parent_dir_name);
a2f18f
+                    inst->inst_parent_dir_name = slapi_ch_strdup(dbdir);
a2f18f
+                }
a2f18f
                 rval_main |= dbverify_ext(inst, verbose);
a2f18f
             }
a2f18f
             else
a2f18f
@@ -235,6 +243,11 @@ ldbm_back_dbverify( Slapi_PBlock *pb )
a2f18f
                             inst->inst_name);
a2f18f
                 continue; /* skip this instance and go to the next*/
a2f18f
             }
a2f18f
+            if (dbdir){
a2f18f
+                /* verifying backup */
a2f18f
+                slapi_ch_free_string(&inst->inst_parent_dir_name);
a2f18f
+                inst->inst_parent_dir_name = slapi_ch_strdup(dbdir);
a2f18f
+            }
a2f18f
             rval_main |= dbverify_ext(inst, verbose);
a2f18f
         }
a2f18f
     }
a2f18f
diff --git a/ldap/servers/slapd/main.c b/ldap/servers/slapd/main.c
a2f18f
index 9016144..922de97 100644
a2f18f
--- a/ldap/servers/slapd/main.c
a2f18f
+++ b/ldap/servers/slapd/main.c
a2f18f
@@ -435,13 +435,15 @@ static int ldif_printkey = EXPORT_PRINTKEY|EXPORT_APPENDMODE;
a2f18f
 static char *archive_name = NULL;
a2f18f
 static int db2ldif_dump_replica = 0;
a2f18f
 static int db2ldif_dump_uniqueid = 1;
a2f18f
-static int ldif2db_generate_uniqueid = SLAPI_UNIQUEID_GENERATE_TIME_BASED;	
a2f18f
-static int dbverify_verbose = 0;
a2f18f
+static int ldif2db_generate_uniqueid = SLAPI_UNIQUEID_GENERATE_TIME_BASED;
a2f18f
 static char *ldif2db_namespaceid = NULL;
a2f18f
 int importexport_encrypt = 0;
a2f18f
 static int upgradedb_flags = 0;
a2f18f
 static int upgradednformat_dryrun = 0;
a2f18f
 static int is_quiet = 0;
a2f18f
+/* dbverify options */
a2f18f
+static int dbverify_verbose = 0;
a2f18f
+static char *dbverify_dbdir = NULL;
a2f18f
 
a2f18f
 /* taken from idsktune */
a2f18f
 #if defined(__sun)
a2f18f
@@ -1301,13 +1303,14 @@ process_command_line(int argc, char **argv, char *myname,
a2f18f
 		{"dryrun",ArgNone,'N'},
a2f18f
 		{0,0,0}};
a2f18f
 
a2f18f
-	char *opts_dbverify = "vVfd:n:D:"; 
a2f18f
+	char *opts_dbverify = "vVfd:n:D:a:";
a2f18f
 	struct opt_ext long_options_dbverify[] = {
a2f18f
 		{"version",ArgNone,'v'},
a2f18f
 		{"debug",ArgRequired,'d'},
a2f18f
 		{"backend",ArgRequired,'n'},
a2f18f
 		{"configDir",ArgRequired,'D'},
a2f18f
 		{"verbose",ArgNone,'V'},
a2f18f
+		{"dbdir",ArgRequired,'a'},
a2f18f
 		{0,0,0}};
a2f18f
 
a2f18f
 	char *opts_referral = "vd:p:r:SD:"; 
a2f18f
@@ -1674,7 +1677,11 @@ process_command_line(int argc, char **argv, char *myname,
a2f18f
 			break;
a2f18f
 
a2f18f
 		case 'a':	/* archive pathname for db */
a2f18f
-			archive_name = optarg_ext;
a2f18f
+			if ( slapd_exemode == SLAPD_EXEMODE_DBVERIFY ) {
a2f18f
+				dbverify_dbdir = optarg_ext;
a2f18f
+			} else {
a2f18f
+				archive_name = optarg_ext;
a2f18f
+			}
a2f18f
 			break;
a2f18f
 
a2f18f
 		case 'Z':
a2f18f
@@ -2688,7 +2695,8 @@ slapd_exemode_dbverify()
a2f18f
     pb.pb_plugin = backend_plugin;
a2f18f
     pb.pb_instance_name = (char *)cmd_line_instance_names;
a2f18f
     pb.pb_task_flags = SLAPI_TASK_RUNNING_FROM_COMMANDLINE;
a2f18f
-    
a2f18f
+    pb.pb_dbverify_dbdir = dbverify_dbdir;
a2f18f
+
a2f18f
     if ( backend_plugin->plg_dbverify != NULL ) {
a2f18f
         return_value = (*backend_plugin->plg_dbverify)( &pb );
a2f18f
     } else {
a2f18f
diff --git a/ldap/servers/slapd/pblock.c b/ldap/servers/slapd/pblock.c
a2f18f
index c10f788..bf57a33 100644
a2f18f
--- a/ldap/servers/slapd/pblock.c
a2f18f
+++ b/ldap/servers/slapd/pblock.c
a2f18f
@@ -5,7 +5,7 @@
a2f18f
  * All rights reserved.
a2f18f
  *
a2f18f
  * License: GPL (version 3 or any later version).
a2f18f
- * See LICENSE for details. 
a2f18f
+ * See LICENSE for details.
a2f18f
  * END COPYRIGHT BLOCK **/
a2f18f
 
a2f18f
 #ifdef HAVE_CONFIG_H
a2f18f
@@ -1677,6 +1677,11 @@ slapi_pblock_get( Slapi_PBlock *pblock, int arg, void *value )
a2f18f
 		(*(IFP*)value) = pblock->pb_txn_ruv_mods_fn;
a2f18f
 		break;
a2f18f
 
a2f18f
+	/* dbverify */
a2f18f
+	case SLAPI_DBVERIFY_DBDIR:
a2f18f
+		(*(char **)value) = pblock->pb_dbverify_dbdir;
a2f18f
+		break;
a2f18f
+
a2f18f
 	/* Search results set */
a2f18f
 	case SLAPI_SEARCH_RESULT_SET:
a2f18f
 		if(pblock->pb_op!=NULL)
a2f18f
@@ -3520,6 +3525,11 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
a2f18f
 		pblock->pb_aci_target_check = *((int *) value);
a2f18f
 		break;
a2f18f
 
a2f18f
+	/* dbverify */
a2f18f
+	case SLAPI_DBVERIFY_DBDIR:
a2f18f
+		pblock->pb_dbverify_dbdir = (char *) value;
a2f18f
+		break;
a2f18f
+
a2f18f
 	default:
a2f18f
 		LDAPDebug( LDAP_DEBUG_ANY,
a2f18f
 		    "Unknown parameter block argument %d\n", arg, 0, 0 );
a2f18f
diff --git a/ldap/servers/slapd/slap.h b/ldap/servers/slapd/slap.h
a2f18f
index 6d1ad7b..823568d 100644
a2f18f
--- a/ldap/servers/slapd/slap.h
a2f18f
+++ b/ldap/servers/slapd/slap.h
a2f18f
@@ -1600,6 +1600,8 @@ typedef struct slapi_pblock {
a2f18f
 	int             pb_seq_type;
a2f18f
 	char            *pb_seq_attrname;
a2f18f
 	char            *pb_seq_val;
a2f18f
+	/* dbverify argument */
a2f18f
+	char *pb_dbverify_dbdir;
a2f18f
 	/* ldif2db arguments */
a2f18f
 	char		*pb_ldif_file;
a2f18f
 	int		pb_removedupvals;
a2f18f
diff --git a/ldap/servers/slapd/slapi-plugin.h b/ldap/servers/slapd/slapi-plugin.h
a2f18f
index a8c7a4a..6b04610 100644
a2f18f
--- a/ldap/servers/slapd/slapi-plugin.h
a2f18f
+++ b/ldap/servers/slapd/slapi-plugin.h
a2f18f
@@ -7289,6 +7289,9 @@ typedef struct slapi_plugindesc {
a2f18f
 /* ACI Target Check */
a2f18f
 #define SLAPI_ACI_TARGET_CHECK      1946
a2f18f
 
a2f18f
+/* dbverify */
a2f18f
+#define SLAPI_DBVERIFY_DBDIR		1947
a2f18f
+
a2f18f
 /* convenience macros for checking modify operation types */
a2f18f
 #define SLAPI_IS_MOD_ADD(x) (((x) & ~LDAP_MOD_BVALUES) == LDAP_MOD_ADD)
a2f18f
 #define SLAPI_IS_MOD_DELETE(x) (((x) & ~LDAP_MOD_BVALUES) == LDAP_MOD_DELETE)
a2f18f
diff --git a/man/man8/dbverify.8 b/man/man8/dbverify.8
a2f18f
index 30d6933..c74747a 100644
a2f18f
--- a/man/man8/dbverify.8
a2f18f
+++ b/man/man8/dbverify.8
a2f18f
@@ -31,6 +31,9 @@ one instance on the system, this option can be skipped.
a2f18f
 .B \fB\-n\fR \fIBackend Name\fR
a2f18f
 The name of the LDBM database to reindex.  Example: userRoot
a2f18f
 .TP
a2f18f
+.B \fB\-a\fR \fIDatabase Directory\fR
a2f18f
+Location of database if it is different than what is in the server configuration(e.g. backup directories)
a2f18f
+.TP
a2f18f
 .B \fB\-d\fR \fIDebug Level\fR
a2f18f
 Sets the debugging level.
a2f18f
 .TP
a2f18f
-- 
a2f18f
1.9.3
a2f18f