+
+#ifdef ENABLE_REWRITE
+ /*
+ * Sets a cookie for the rewrite session
+ */
+ ( void )rewrite_session_init( li->rwinfo, conn );
+#endif /* ENABLE_REWRITE */
+
+ if ( lc->conn->c_cdn != NULL && lc->conn->c_cdn[0] != '\0' ) {
+
+ /*
+ * Rewrite the bind dn if needed
+ */
+#ifdef ENABLE_REWRITE
+ lc->bound_dn = NULL;
+ switch ( rewrite_session( li->rwinfo, "bindDn",
+ lc->conn->c_cdn, conn,
+ &lc->bound_dn ) ) {
+ case REWRITE_REGEXEC_OK:
+ if ( lc->bound_dn == NULL ) {
+ lc->bound_dn =
+ ch_strdup( lc->conn->c_cdn );
+ }
+#ifdef NEW_LOGGING
+ LDAP_LOG(( "backend", LDAP_LEVEL_DETAIL1,
+ "[rw] bindDn: \"%s\" ->"
+ " \"%s\"\n%s",
+ lc->conn->c_cdn,
+ lc->bound_dn ));
+#else /* !NEW_LOGGING */
+ Debug( LDAP_DEBUG_ARGS,
+ "rw> bindDn: \"%s\" ->"
+ " \"%s\"\n%s",
+ lc->conn->c_cdn,
+ lc->bound_dn, "" );
+#endif /* !NEW_LOGGING */
+ break;
+
+ case REWRITE_REGEXEC_UNWILLING:
+ send_ldap_result( conn, op,
+ LDAP_UNWILLING_TO_PERFORM,
+ NULL, "Unwilling to perform",
+ NULL, NULL );
+ return( NULL );
+
+ case REWRITE_REGEXEC_ERR:
+ send_ldap_result( conn, op,
+ LDAP_OPERATIONS_ERROR,
+ NULL, "Operations error",
+ NULL, NULL );
+ return( NULL );
+ }
+#else /* !ENABLE_REWRITE */
+ lc->bound_dn = ldap_back_dn_massage( li,
+ ch_strdup( lc->conn->c_cdn ), 0 );
+#endif /* !ENABLE_REWRITE */
+ } else {
+ lc->bound_dn = NULL;
+ }