+int
+send_search_reference(
+ Backend *be,
+ Connection *conn,
+ Operation *op,
+ Entry *e,
+ BerVarray refs,
+ LDAPControl **ctrls,
+ BerVarray *v2refs
+)
+{
+ char berbuf[256];
+ BerElement *ber = (BerElement *)berbuf;
+ int rc;
+ int bytes;
+
+ AttributeDescription *ad_ref = slap_schema.si_ad_ref;
+ AttributeDescription *ad_entry = slap_schema.si_ad_entry;
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ENTRY,
+ "send_search_reference: conn %lu dn=\"%s\"\n",
+ op->o_connid, e->e_dn, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE,
+ "=> send_search_reference: dn=\"%s\"\n",
+ e->e_dn, 0, 0 );
+#endif
+
+
+ if ( ! access_allowed( be, conn, op, e,
+ ad_entry, NULL, ACL_READ, NULL ) )
+ {
+#ifdef NEW_LOGGING
+ LDAP_LOG( ACL, INFO,
+ "send_search_reference: conn %lu "
+ "access to entry %s not allowed\n", op->o_connid, e->e_dn, 0 );
+#else
+ Debug( LDAP_DEBUG_ACL,
+ "send_search_reference: access to entry not allowed\n",
+ 0, 0, 0 );
+#endif
+
+ return( 1 );
+ }
+
+ if ( ! access_allowed( be, conn, op, e,
+ ad_ref, NULL, ACL_READ, NULL ) )
+ {
+#ifdef NEW_LOGGING
+ LDAP_LOG( ACL, INFO,
+ "send_search_reference: conn %lu access "
+ "to reference not allowed.\n", op->o_connid, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ACL,
+ "send_search_reference: access "
+ "to reference not allowed\n",
+ 0, 0, 0 );
+#endif
+
+ return( 1 );
+ }
+
+ if( refs == NULL ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ERR,
+ "send_search_reference: conn %lu null ref in (%s).\n",
+ op->o_connid, e->e_dn, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "send_search_reference: null ref in (%s)\n",
+ e->e_dn, 0, 0 );
+#endif
+
+ return( 1 );
+ }
+
+ if( op->o_protocol < LDAP_VERSION3 ) {
+ /* save the references for the result */
+ if( refs[0].bv_val != NULL ) {
+ value_add( v2refs, refs );
+ }
+ return 0;
+ }
+
+ ber_init_w_nullc( ber, LBER_USE_DER );
+
+ rc = ber_printf( ber, "{it{W}" /*"}"*/ , op->o_msgid,
+ LDAP_RES_SEARCH_REFERENCE, refs );
+
+ if( rc != -1 && ctrls != NULL ) {
+ rc = send_ldap_controls( ber, ctrls );
+ }
+
+ if( rc != -1 ) {
+ rc = ber_printf( ber, /*"{"*/ "N}", op->o_msgid,
+ LDAP_RES_SEARCH_REFERENCE, refs );
+ }
+
+ if ( rc == -1 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ERR,
+ "send_search_reference: conn %lu "
+ "ber_printf failed.\n", op->o_connid, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY,
+ "send_search_reference: ber_printf failed\n", 0, 0, 0 );
+#endif
+
+ ber_free_buf( ber );
+ send_ldap_result( conn, op, LDAP_OTHER,
+ NULL, "encode DN error", NULL, NULL );
+ return -1;
+ }
+
+ bytes = send_ldap_ber( conn, ber );
+ ber_free_buf( ber );
+
+ ldap_pvt_thread_mutex_lock( &num_sent_mutex );
+ num_bytes_sent += bytes;
+ num_refs_sent++;
+ num_pdu_sent++;
+ ldap_pvt_thread_mutex_unlock( &num_sent_mutex );
+
+ Statslog( LDAP_DEBUG_STATS2, "conn=%lu op=%lu REF dn=\"%s\"\n",
+ conn->c_connid, op->o_opid, e->e_dn, 0, 0 );
+
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ENTRY,
+ "send_search_reference: conn %lu exit.\n", op->o_connid, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_TRACE, "<= send_search_reference\n", 0, 0, 0 );
+#endif
+
+ return 0;
+}
+
+