Explorar o código

Bug 630094 - (cov#15452) Remove NULL checking for op_string

There is no chance for op_string to be NULL if "rc == LDAP_SUCCESS"
since op_string is set for all operation types in the switch statement,
which is the only place that rc can be set to something other that the
value of -1 that it is initialized to.

We can just skip the NULL checking for op_string in the calls to
slapi_log_error().  I also fixed the indentation to help me read
the code easier.
Nathan Kinder %!s(int64=15) %!d(string=hai) anos
pai
achega
72b41da04e
Modificáronse 1 ficheiros con 27 adicións e 26 borrados
  1. 27 26
      ldap/servers/plugins/replication/windows_connection.c

+ 27 - 26
ldap/servers/plugins/replication/windows_connection.c

@@ -374,11 +374,10 @@ windows_perform_operation(Repl_Connection *conn, int optype, const char *dn,
 				char *s = NULL;
 				char *s = NULL;
 		
 		
 				rc = slapi_ldap_get_lderrno(conn->ld, NULL, &s);
 				rc = slapi_ldap_get_lderrno(conn->ld, NULL, &s);
-                slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
+				slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
 						"%s: Received error %d: %s for %s operation\n",
 						"%s: Received error %d: %s for %s operation\n",
 						agmt_get_long_name(conn->agmt),
 						agmt_get_long_name(conn->agmt),
-						rc, s ? s : "NULL",
-						op_string ? op_string : "NULL");
+						rc, s ? s : "NULL", op_string);
 				conn->last_ldap_error = rc;
 				conn->last_ldap_error = rc;
 				/* some errors will require a disconnect and retry the connection
 				/* some errors will require a disconnect and retry the connection
 				   later */
 				   later */
@@ -399,7 +398,7 @@ windows_perform_operation(Repl_Connection *conn, int optype, const char *dn,
 				char *errmsg = NULL;
 				char *errmsg = NULL;
 				char **referrals = NULL;
 				char **referrals = NULL;
 				char *matched = NULL;
 				char *matched = NULL;
-                char *ptr;
+				char *ptr;
 
 
 				rc = ldap_parse_result(conn->ld, res, &err, &matched,
 				rc = ldap_parse_result(conn->ld, res, &err, &matched,
 									   &errmsg, &referrals, &loc_returned_controls,
 									   &errmsg, &referrals, &loc_returned_controls,
@@ -448,34 +447,36 @@ windows_perform_operation(Repl_Connection *conn, int optype, const char *dn,
 					}
 					}
 					return_value = LDAP_SUCCESS == conn->last_ldap_error ? CONN_OPERATION_SUCCESS : CONN_OPERATION_FAILED;
 					return_value = LDAP_SUCCESS == conn->last_ldap_error ? CONN_OPERATION_SUCCESS : CONN_OPERATION_FAILED;
 				}
 				}
-                /* remove extra newlines from AD error message */
-                for (ptr = errmsg; ptr && *ptr; ++ptr) {
-                    if ((*ptr == '\n') || (*ptr == '\r')) {
-                        *ptr = ' ';
-                    }
-                }
-                /* handle special case of constraint violation - give admin
-                   enough information to allow them to fix the problem
-                   and retry - bug 170350 */
-                if (conn->last_ldap_error == LDAP_CONSTRAINT_VIOLATION) {
-                    char ebuf[BUFSIZ];
-                    slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
+
+				/* remove extra newlines from AD error message */
+				for (ptr = errmsg; ptr && *ptr; ++ptr) {
+					if ((*ptr == '\n') || (*ptr == '\r')) {
+						*ptr = ' ';
+					}
+				}
+
+				/* handle special case of constraint violation - give admin
+				 * enough information to allow them to fix the problem
+				 * and retry - bug 170350 */
+				if (conn->last_ldap_error == LDAP_CONSTRAINT_VIOLATION) {
+					char ebuf[BUFSIZ];
+					slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
 						"%s: Received error [%s] when attempting to %s"
 						"%s: Received error [%s] when attempting to %s"
-                        " entry [%s]: Please correct the attribute specified "
-                        "in the error message.  Refer to the Windows Active "
-                        "Directory docs for more information.\n",
+						" entry [%s]: Please correct the attribute specified "
+						"in the error message.  Refer to the Windows Active "
+						"Directory docs for more information.\n",
 						agmt_get_long_name(conn->agmt),
 						agmt_get_long_name(conn->agmt),
-						errmsg, op_string == NULL ? "" : op_string,
-						escape_string(dn, ebuf));
-                } else {
-                    slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
+						errmsg, op_string, escape_string(dn, ebuf));
+				} else {
+					slapi_log_error(SLAPI_LOG_REPL, repl_plugin_name,
 						"%s: Received result code %d (%s) for %s operation %s%s\n",
 						"%s: Received result code %d (%s) for %s operation %s%s\n",
 						agmt_get_long_name(conn->agmt),
 						agmt_get_long_name(conn->agmt),
 						conn->last_ldap_error, errmsg,
 						conn->last_ldap_error, errmsg,
-						op_string == NULL ? "" : op_string,
+						op_string,
 						extra_op_string == NULL ? "" : extra_op_string,
 						extra_op_string == NULL ? "" : extra_op_string,
 						extra_op_string ==  NULL ? "" : " ");
 						extra_op_string ==  NULL ? "" : " ");
-                }
+				}
+
 				/*
 				/*
 				 * XXXggood do I need to free matched, referrals,
 				 * XXXggood do I need to free matched, referrals,
 				 * anything else? Or can I pass NULL for the args
 				 * anything else? Or can I pass NULL for the args
@@ -491,7 +492,7 @@ windows_perform_operation(Repl_Connection *conn, int optype, const char *dn,
 		}
 		}
 		else
 		else
 		{
 		{
-            slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
+			slapi_log_error(SLAPI_LOG_FATAL, repl_plugin_name,
 					"%s: Failed to send %s operation: LDAP error %d (%s)\n",
 					"%s: Failed to send %s operation: LDAP error %d (%s)\n",
 					agmt_get_long_name(conn->agmt),
 					agmt_get_long_name(conn->agmt),
 					op_string ? op_string : "NULL", rc, ldap_err2string(rc));
 					op_string ? op_string : "NULL", rc, ldap_err2string(rc));