andykimpe / rpms / 389-ds-base

Forked from rpms/389-ds-base 5 months ago
Clone
Blob Blame History Raw
From 217f5abb8cc586378fff66bbbb5dfb9d87a948f7 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Wed, 5 Aug 2015 16:31:49 -0400
Subject: [PATCH 354/363] 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)

Conflicts:
	ldap/servers/slapd/pblock.c

(cherry picked from commit 6878a6cb355ff96fc390d71528978420ffc316e7)

Conflicts:
	ldap/servers/slapd/pblock.c
	ldap/servers/slapd/slapi-plugin.h

(cherry picked from commit bb704aac1868ab719d0823871cf0b677e67fcf41)

Conflicts:
	ldap/admin/src/scripts/dbverify.in
	ldap/admin/src/scripts/verify-db.pl.in
	ldap/servers/slapd/main.c
	man/man8/dbverify.8

(cherry picked from commit cf8c8d78990b66fd7005839e843dfe795eb17327)
---
 ldap/admin/src/scripts/template-dbverify.in     |  6 +++++-
 ldap/admin/src/scripts/template-verify-db.pl.in | 10 +++++++++-
 ldap/servers/slapd/back-ldbm/dbverify.c         | 13 +++++++++++++
 ldap/servers/slapd/main.c                       | 18 +++++++++++++-----
 ldap/servers/slapd/pblock.c                     | 10 ++++++++++
 ldap/servers/slapd/slap.h                       |  2 ++
 ldap/servers/slapd/slapi-plugin.h               |  3 +++
 7 files changed, 55 insertions(+), 7 deletions(-)

diff --git a/ldap/admin/src/scripts/template-dbverify.in b/ldap/admin/src/scripts/template-dbverify.in
index 8c1a98e..04ef555 100755
--- a/ldap/admin/src/scripts/template-dbverify.in
+++ b/ldap/admin/src/scripts/template-dbverify.in
@@ -28,8 +28,12 @@ do
         args=$args" "$1
     elif [ "$1" = "-V" ]; then
         args=$args" "$1
+    elif [ "$1" = "-a" ]; then
+        args=$args" "$1
+        shift
+        args=$args" "$1
     else
-        echo "Usage: dbverify [-n backend_instance] [-V]"
+        echo "Usage: dbverify [-n backend_instance] [-a db_file_directory] [-V]"
         echo "Note : if \"-n backend_instance\" is not passed, verify all DBs."
         echo "  -V : verbose"
         exit 1
diff --git a/ldap/admin/src/scripts/template-verify-db.pl.in b/ldap/admin/src/scripts/template-verify-db.pl.in
index c352eb2..f48d94f 100644
--- a/ldap/admin/src/scripts/template-verify-db.pl.in
+++ b/ldap/admin/src/scripts/template-verify-db.pl.in
@@ -38,6 +38,8 @@
 # END COPYRIGHT BLOCK
 #
 
+my $customer_dbdir = 0;
+
 sub usage
 {
   print "Usage: $0 [ -a <fullpath_to_db_dir> ]\n";
@@ -164,6 +166,8 @@ print("*****************************************************************\n");
 
 if ( "$startpoint" eq "" ) {
   $startpoint = "{{DB-DIR}}";
+} else {
+  $custom_dbdir = 1;
 }
 # get dirs having DBVERSION
 my $dbdirs = getDbDir($startpoint);
@@ -215,7 +219,11 @@ for (my $i = 0; "$$dbdirs[$i]" ne ""; $i++)
 
 # Check db files by db_verify
 print "Verify db files ... ";
-open(DBVERIFY, "dbverify $thisdb 2>&1 1> $NULL |");
+if ($custom_dbdir){
+  open(DBVERIFY, "dbverify $thisdb -a $startpoint 2>&1 1> $NULL |");
+} else {
+  open(DBVERIFY, "dbverify $thisdb 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 ffd5900..b0b2d78 100644
--- a/ldap/servers/slapd/back-ldbm/dbverify.c
+++ b/ldap/servers/slapd/back-ldbm/dbverify.c
@@ -214,13 +214,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))
     {
@@ -239,6 +242,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
@@ -263,6 +271,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 5d3e7e7..2442610 100644
--- a/ldap/servers/slapd/main.c
+++ b/ldap/servers/slapd/main.c
@@ -490,12 +490,14 @@ 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;
+/* dbverify options */
+static int dbverify_verbose = 0;
+static char *dbverify_dbdir = NULL;
 
 /* taken from idsktune */
 #if defined(__sun)
@@ -1449,13 +1451,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:"; 
@@ -1841,7 +1844,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':
@@ -2850,7 +2857,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 849c20e..b12881b 100644
--- a/ldap/servers/slapd/pblock.c
+++ b/ldap/servers/slapd/pblock.c
@@ -1699,6 +1699,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)
@@ -3523,6 +3528,11 @@ slapi_pblock_set( Slapi_PBlock *pblock, int arg, void *value )
 		pblock->pb_paged_results_index = *(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 c298033..da90fe6 100644
--- a/ldap/servers/slapd/slap.h
+++ b/ldap/servers/slapd/slap.h
@@ -1548,6 +1548,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 5c737ad..75d5aa9 100644
--- a/ldap/servers/slapd/slapi-plugin.h
+++ b/ldap/servers/slapd/slapi-plugin.h
@@ -6889,6 +6889,9 @@ typedef struct slapi_plugindesc {
 /* Simple paged results index */
 #define SLAPI_PAGED_RESULTS_INDEX   1945
 
+/* 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)
-- 
2.4.3