From 501ce48035ae6987fb6fca52cffc2ebac7483fd2 Mon Sep 17 00:00:00 2001
From: Mark Reynolds <mreynolds@redhat.com>
Date: Mon, 25 Mar 2013 14:06:23 -0400
Subject: [PATCH] Ticket 587 - Replication error messages in the DS error logs

Bug Description:  Replicand DNA error message are seen as vague.

Fix Description:  Moved some DNA plugin errors mesages to log as SLAPI_LOG_PLUGIN,
                  instead of SLAPI_LOG_FATAL.  Made some replication errors
                  more human readable.  Also, improved NSPR error str function
                  to check for zero result and not report "unknown" error.

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

Reviewed by: ?
---
 ldap/servers/plugins/dna/dna.c                     |    4 ++--
 .../servers/plugins/replication/repl5_connection.c |    4 ++--
 .../plugins/replication/repl5_inc_protocol.c       |    5 +++--
 .../plugins/replication/repl5_protocol_util.c      |    4 ++--
 .../plugins/replication/windows_inc_protocol.c     |    5 +++--
 ldap/servers/slapd/entry.c                         |    5 +++--
 ldap/servers/slapd/errormap.c                      |    8 ++++++--
 ldap/servers/slapd/ldaputil.c                      |   15 ++++++++-------
 8 files changed, 29 insertions(+), 21 deletions(-)

diff --git a/ldap/servers/plugins/dna/dna.c b/ldap/servers/plugins/dna/dna.c
index 080e357..5f073bf 100644
--- a/ldap/servers/plugins/dna/dna.c
+++ b/ldap/servers/plugins/dna/dna.c
@@ -1639,7 +1639,7 @@ static int dna_request_range(struct configEntry *config_entry,
                           NULL, NULL, NULL, NULL);
 
     if (ret != LDAP_SUCCESS) {
-        slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+        slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
                         "dna_request_range: Error binding "
                         " to replica server %s:%u. [error %d]\n",
                         server->host, server->port, ret);
@@ -2947,7 +2947,7 @@ _dna_pre_op_add(Slapi_PBlock *pb, Slapi_Entry *e, char **errstr)
                  * really a soft failure. */
                 if ((config_entry->next_range_lower == 0) &&
                     (config_entry->remaining <= config_entry->threshold)) {
-                    slapi_log_error(SLAPI_LOG_FATAL, DNA_PLUGIN_SUBSYSTEM,
+                    slapi_log_error(SLAPI_LOG_PLUGIN, DNA_PLUGIN_SUBSYSTEM,
                                     "dna_pre_op: Passed threshold of %" 
                                     NSPRIu64 " remaining values "
                                     "for range %s. (%" NSPRIu64 " values remain)\n",
diff --git a/ldap/servers/plugins/replication/repl5_connection.c b/ldap/servers/plugins/replication/repl5_connection.c
index 76c77c9..b8b542e 100644
--- a/ldap/servers/plugins/replication/repl5_connection.c
+++ b/ldap/servers/plugins/replication/repl5_connection.c
@@ -1842,7 +1842,7 @@ bind_and_check_pwp(Repl_Connection *conn, char * binddn, char *password)
 							"%s: Replication bind with %s auth failed: LDAP error %d (%s) (%s)\n",
 							agmt_get_long_name(conn->agmt),
 							mech ? mech : "SIMPLE", rc,
-							ldap_err2string(rc), errmsg);
+							ldap_err2string(rc), errmsg ? errmsg : "");
 		} else {
 			char *errmsg = NULL;
 			/* errmsg is a pointer directly into the ld structure - do not free */
@@ -1851,7 +1851,7 @@ bind_and_check_pwp(Repl_Connection *conn, char * binddn, char *password)
 							"%s: Replication bind with %s auth failed: LDAP error %d (%s) (%s)\n",
 							agmt_get_long_name(conn->agmt),
 							mech ? mech : "SIMPLE", rc,
-							ldap_err2string(rc), errmsg);
+							ldap_err2string(rc), errmsg ? errmsg : "");
 		}
 
 		return (CONN_OPERATION_FAILED);
diff --git a/ldap/servers/plugins/replication/repl5_inc_protocol.c b/ldap/servers/plugins/replication/repl5_inc_protocol.c
index c3d027b..222bb97 100644
--- a/ldap/servers/plugins/replication/repl5_inc_protocol.c
+++ b/ldap/servers/plugins/replication/repl5_inc_protocol.c
@@ -1005,8 +1005,9 @@ repl5_inc_run(Private_Repl_Protocol *prp)
                   break;
               case EXAMINE_RUV_GENERATION_MISMATCH:
                   slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
-                      "%s: Replica has a different generation ID than the local data.\n",
-                      agmt_get_long_name(prp->agmt));
+                      "%s: The remote replica has a different database generation ID than "
+                      "the local database.  You may have to reinitialize the remote replica, "
+                      "or the local replica.\n", agmt_get_long_name(prp->agmt));
                   next_state = STATE_BACKOFF_START;
                   break;
               case EXAMINE_RUV_REPLICA_TOO_OLD:
diff --git a/ldap/servers/plugins/replication/repl5_protocol_util.c b/ldap/servers/plugins/replication/repl5_protocol_util.c
index 30d211a..56f8532 100644
--- a/ldap/servers/plugins/replication/repl5_protocol_util.c
+++ b/ldap/servers/plugins/replication/repl5_protocol_util.c
@@ -590,8 +590,8 @@ release_replica(Private_Repl_Protocol *prp)
 		int operation, error;
 		conn_get_error(prp->conn, &operation, &error);
 		slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
-			"%s: Warning: unable to receive endReplication extended operation response (%s)\n",
-			agmt_get_long_name(prp->agmt),
+			"%s: Warning: Attempting to release replica, but unable to receive endReplication extended "
+			"operation response from the replica. Error %d (%s)\n", agmt_get_long_name(prp->agmt), error,
 			error ? ldap_err2string(error) : "unknown error");
 	}
 	else
diff --git a/ldap/servers/plugins/replication/windows_inc_protocol.c b/ldap/servers/plugins/replication/windows_inc_protocol.c
index 38d9011..cf979cc 100644
--- a/ldap/servers/plugins/replication/windows_inc_protocol.c
+++ b/ldap/servers/plugins/replication/windows_inc_protocol.c
@@ -797,8 +797,9 @@ windows_inc_run(Private_Repl_Protocol *prp)
 	    break;
 	  case EXAMINE_RUV_GENERATION_MISMATCH:
 	    slapi_log_error(SLAPI_LOG_FATAL, windows_repl_plugin_name,
-			"%s: Replica has a different generation ID than the local data.\n",
-		    agmt_get_long_name(prp->agmt));
+	    	"%s: The remote replica has a different database generation ID than "
+	    	"the local database.  You may have to reinitialize the remote replica, "
+	    	"or the local replica.\n", agmt_get_long_name(prp->agmt));
 	    next_state = STATE_BACKOFF_START;
 	    break;
 	  case EXAMINE_RUV_REPLICA_TOO_OLD:
diff --git a/ldap/servers/slapd/entry.c b/ldap/servers/slapd/entry.c
index ebd49de..17af1bf 100644
--- a/ldap/servers/slapd/entry.c
+++ b/ldap/servers/slapd/entry.c
@@ -801,8 +801,9 @@ str2entry_dupcheck( const char *rawdn, char *s, int flags, int read_stateinfo )
 		bvtype = bv_null;
 		bvvalue = bv_null;
 		if ( slapi_ldif_parse_line( s, &bvtype, &bvvalue, &freeval ) < 0 ) {
-		    LDAPDebug1Arg(LDAP_DEBUG_ANY,
-		                  "Warning: ignoring invalid line \"%s\"...\n", s);
+		    LDAPDebug(LDAP_DEBUG_ANY,
+		                  "Warning: Entry (%s), ignoring invalid line \"%s\"...\n",
+		                  rawdn ? rawdn : "", s, 0);
 		    continue;
 		}
 		type = bvtype.bv_val;
diff --git a/ldap/servers/slapd/errormap.c b/ldap/servers/slapd/errormap.c
index c585d25..d685fbd 100644
--- a/ldap/servers/slapd/errormap.c
+++ b/ldap/servers/slapd/errormap.c
@@ -66,8 +66,12 @@ slapd_pr_strerror( const int prerrno )
 {
     char	*s;
 
-    if (( s = (char *)SECU_Strerror( (PRErrorCode)prerrno )) == NULL ) {
-	s = "unknown";
+    if(prerrno == 0){
+        s = "no error";
+    } else {
+        if (( s = (char *)SECU_Strerror( (PRErrorCode)prerrno )) == NULL ) {
+             s = "unknown error";
+        }
     }
 
     return( s );
diff --git a/ldap/servers/slapd/ldaputil.c b/ldap/servers/slapd/ldaputil.c
index 1c67e51..3ca1139 100644
--- a/ldap/servers/slapd/ldaputil.c
+++ b/ldap/servers/slapd/ldaputil.c
@@ -1088,7 +1088,7 @@ slapi_ldap_bind(
 	    char *copy = NULL;
 	    char *ptr = NULL;
 	    int myerrno = errno;
-	    int gaierr;
+	    int gaierr = 0;
 
 	    ldap_get_option(ld, LDAP_OPT_HOST_NAME, &myhostname);
 	    if (myhostname) {
@@ -1110,7 +1110,8 @@ slapi_ldap_bind(
 	    }
 	    slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
 			    "Error: could not send bind request for id "
-			    "[%s] mech [%s]: error %d (%s) %d (%s) %d (%s \"%s\")\n",
+			    "[%s] authentication mechanism [%s]: error %d (%s), system error %d (%s), "
+			    "network error %d (%s, host \"%s\")\n",
 			    bindid ? bindid : "(anon)",
 			    mech ? mech : "SIMPLE",
 			    rc, ldap_err2string(rc),
@@ -1130,7 +1131,7 @@ slapi_ldap_bind(
 		rc = slapi_ldap_get_lderrno(ld, NULL, NULL);
 		slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
 				"Error reading bind response for id "
-				"[%s] mech [%s]: error %d (%s) errno %d (%s)\n",
+				"[%s] authentication mechanism [%s]: error %d (%s) errno %d (%s)\n",
 				bindid ? bindid : "(anon)",
 				mech ? mech : "SIMPLE",
 				rc, ldap_err2string(rc), errno, slapd_system_strerror(errno));
@@ -1139,7 +1140,7 @@ slapi_ldap_bind(
 		rc = LDAP_TIMEOUT;
 		slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
 				"Error: timeout after [%ld.%ld] seconds reading "
-				"bind response for [%s] mech [%s]\n",
+				"bind response for [%s] authentication mechanism [%s]\n",
 				timeout ? timeout->tv_sec : 0,
 				timeout ? timeout->tv_usec : 0,
 				bindid ? bindid : "(anon)",
@@ -1161,7 +1162,7 @@ slapi_ldap_bind(
             rc = err;
             slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
                             "Error: could not bind id "
-                            "[%s] mech [%s]: error %d (%s) errno %d (%s)\n",
+                            "[%s] authentication mechanism [%s]: error %d (%s) errno %d (%s)\n",
                             bindid ? bindid : "(anon)",
                             mech ? mech : "SIMPLE",
                             rc, ldap_err2string(rc), errno, slapd_system_strerror(errno));
@@ -1174,7 +1175,7 @@ slapi_ldap_bind(
 		rc = slapi_ldap_get_lderrno(ld, NULL, NULL);
 		slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
 				"Error: could not read bind results for id "
-				"[%s] mech [%s]: error %d (%s) errno %d (%s)\n",
+				"[%s] authentication mechanism [%s]: error %d (%s) errno %d (%s)\n",
 				bindid ? bindid : "(anon)",
 				mech ? mech : "SIMPLE",
 				rc, ldap_err2string(rc), errno, slapd_system_strerror(errno));
@@ -1196,7 +1197,7 @@ slapi_ldap_bind(
 	if (LDAP_SUCCESS != rc) {
 	    slapi_log_error(SLAPI_LOG_FATAL, "slapi_ldap_bind",
 			    "Error: could not perform interactive bind for id "
-			    "[%s] mech [%s]: error %d (%s)\n",
+			    "[%s] authentication mechanism [%s]: error %d (%s)\n",
 			    bindid ? bindid : "(anon)",
 			    mech, /* mech cannot be SIMPLE here */
 			    rc, ldap_err2string(rc));
-- 
1.7.1

