andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From a117d87aac507e4002429e5f7aebe61a867da06d Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Wed, 5 Aug 2015 16:31:49 -0400
Subject: [PATCH 34/39] Ticket 48215 - verify_db.pl doesn't verify DB specified
 by -a option

Bug Description:  verify_db.pl -a only uses the db location for
                  checking the transaction logs, because it ends up
                  calling "nsslapd dbverify" which only checks the
                  db files in the server configuration.

Fix Description:  Allow a new argument to be passed to "nsslapd dbverify"
                  that specifies the db parent directory.

https://fedorahosted.org/389/ticket/48215

Reviewed by: nhosoi(Thanks!)

(cherry picked from commit 27fadb75ec1f3b252028ce715cd7fa16da1f6525)
(cherry picked from commit 210071c682751897099e8eb138e5db1e47ac2bae)
---
 ldap/admin/src/scripts/dbverify.in      |  3 ++-
 ldap/admin/src/scripts/verify-db.pl.in  | 17 +++++++++--------
 ldap/servers/slapd/back-ldbm/dbverify.c | 13 +++++++++++++
 ldap/servers/slapd/main.c               | 18 +++++++++++++-----
 ldap/servers/slapd/pblock.c             | 12 +++++++++++-
 ldap/servers/slapd/slap.h               |  2 ++
 ldap/servers/slapd/slapi-plugin.h       |  3 +++
 man/man8/dbverify.8                     |  3 +++
 8 files changed, 56 insertions(+), 15 deletions(-)

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