if (op->o_conn && op->o_conn->c_is_udp &&
op->o_protocol == LDAP_VERSION2 )
{
- rc = ber_printf( ber, "t{ess" /*"}}"*/,
+ rc = ber_printf( ber, "t{ess" /*"}"*/,
rs->sr_tag, rs->sr_err,
rs->sr_matched == NULL ? "" : rs->sr_matched,
rs->sr_text == NULL ? "" : rs->sr_text );
}
#ifdef LDAP_CONNECTIONLESS
- if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2 && rc != -1 ) {
+ if( op->o_conn && op->o_conn->c_is_udp && op->o_protocol == LDAP_VERSION2
+ && rc != -1 )
+ {
rc = ber_printf( ber, /*"{"*/ "N}" );
}
#endif
#ifdef LDAP_CONNECTIONLESS
if (!op->o_conn || op->o_conn->c_is_udp == 0)
#endif
- ber_free_buf( ber );
+ {
+ ber_free_buf( ber );
+ }
goto cleanup;
}
#ifdef LDAP_CONNECTIONLESS
if (!op->o_conn || op->o_conn->c_is_udp == 0)
#endif
- ber_free_buf( ber );
+ {
+ ber_free_buf( ber );
+ }
if ( bytes < 0 ) {
#ifdef NEW_LOGGING
#ifdef LDAP_SLAPI
if ( op->o_pb ) {
slapi_pblock_set( op->o_pb, SLAPI_RESULT_CODE, (void *)rs->sr_err );
- slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED, (void *)rs->sr_matched );
+ slapi_pblock_set( op->o_pb, SLAPI_RESULT_MATCHED,
+ (void *)rs->sr_matched );
slapi_pblock_set( op->o_pb, SLAPI_RESULT_TEXT, (void *)rs->sr_text );
}
#endif /* LDAP_SLAPI */
rs->sr_matched = NULL;
}
+ if ( rs->sr_ref && rs->sr_flags & REP_REF_MUSTBEFREED ) {
+ ber_bvarray_free( rs->sr_ref );
+ rs->sr_ref = NULL;
+ }
+
clean2:
if (op->o_callback) {
slap_callback *sc = op->o_callback;
if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
Statslog( LDAP_DEBUG_STATS,
- "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
- op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err, rs->sr_text ? rs->sr_text : "" );
+ "conn=%lu op=%lu DISCONNECT tag=%lu err=%d text=%s\n",
+ op->o_connid, op->o_opid, rs->sr_tag, rs->sr_err,
+ rs->sr_text ? rs->sr_text : "" );
}
}
rs->sr_type = REP_RESULT;
- assert( !LDAP_API_ERROR( rs->sr_err ) && ( rs->sr_err >= 0 ));
+ assert( !LDAP_API_ERROR( rs->sr_err ));
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ENTRY,
- "send_ldap_result: conn %lu op=%lu p=%d\n",
+ "send_ldap_result: conn=%lu op=%lu p=%d\n",
op->o_connid, op->o_opid, op->o_protocol );
#else
Debug( LDAP_DEBUG_TRACE,
size = i * sizeof(char *) + k;
if ( size > 0 ) {
char *a_flags;
- e_flags = sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
+ e_flags = slap_sl_calloc ( 1, i * sizeof(char *) + k, op->o_tmpmemctx );
if( e_flags == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
- "send_search_entry: conn %lu sl_calloc failed\n",
+ "send_search_entry: conn %lu slap_sl_calloc failed\n",
op->o_connid ? op->o_connid : 0, 0, 0 );
#else
Debug( LDAP_DEBUG_ANY,
- "send_search_entry: sl_calloc failed\n", 0, 0, 0 );
+ "send_search_entry: slap_sl_calloc failed\n", 0, 0, 0 );
#endif
ber_free( ber, 1 );
for ( a = rs->sr_entry->e_attrs, j = 0; a != NULL; a = a->a_next, j++ ) {
AttributeDescription *desc = a->a_desc;
+ int finish = 0;
if ( rs->sr_attrs == NULL ) {
/* all attrs request, skip operational attributes */
}
}
- if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
- ACL_READ, &acl_state ) )
- {
+ if ( op->ors_attrsonly ) {
+ if ( ! access_allowed( op, rs->sr_entry, desc, NULL,
+ ACL_READ, &acl_state ) )
+ {
#ifdef NEW_LOGGING
- LDAP_LOG( ACL, INFO,
- "send_search_entry: conn %lu access to attribute %s not "
- "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
+ LDAP_LOG( ACL, INFO,
+ "send_search_entry: conn %lu access to attribute %s not "
+ "allowed\n", op->o_connid, desc->ad_cname.bv_val, 0 );
#else
- Debug( LDAP_DEBUG_ACL, "acl: "
- "access to attribute %s not allowed\n",
- desc->ad_cname.bv_val, 0, 0 );
+ Debug( LDAP_DEBUG_ACL, "acl: "
+ "access to attribute %s not allowed\n",
+ desc->ad_cname.bv_val, 0, 0 );
#endif
- continue;
- }
+ continue;
+ }
- if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
+ if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
#ifdef NEW_LOGGING
- LDAP_LOG( OPERATION, ERR,
- "send_search_entry: conn %lu ber_printf failed\n",
- op->o_connid, 0, 0 );
+ LDAP_LOG( OPERATION, ERR,
+ "send_search_entry: conn %lu ber_printf failed\n",
+ op->o_connid, 0, 0 );
#else
- Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
+ Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
#endif
- if ( op->o_res_ber == NULL ) ber_free_buf( ber );
- send_ldap_error( op, rs, LDAP_OTHER, "encoding description error");
- goto error_return;
- }
+ if ( op->o_res_ber == NULL ) ber_free_buf( ber );
+ send_ldap_error( op, rs, LDAP_OTHER, "encoding description error");
+ goto error_return;
+ }
+ finish = 1;
- if ( ! op->ors_attrsonly ) {
- for ( i = 0; a->a_vals[i].bv_val != NULL; i++ ) {
+ } else {
+ int first = 1;
+ for ( i = 0; a->a_nvals[i].bv_val != NULL; i++ ) {
if ( ! access_allowed( op, rs->sr_entry,
- desc, &a->a_vals[i], ACL_READ, &acl_state ) )
+ desc, &a->a_nvals[i], ACL_READ, &acl_state ) )
{
#ifdef NEW_LOGGING
LDAP_LOG( ACL, INFO,
continue;
}
+ if ( first ) {
+ first = 0;
+ finish = 1;
+ if (( rc = ber_printf( ber, "{O[" /*]}*/ , &desc->ad_cname )) == -1 ) {
+#ifdef NEW_LOGGING
+ LDAP_LOG( OPERATION, ERR,
+ "send_search_entry: conn %lu ber_printf failed\n",
+ op->o_connid, 0, 0 );
+#else
+ Debug( LDAP_DEBUG_ANY, "ber_printf failed\n", 0, 0, 0 );
+#endif
+
+ if ( op->o_res_ber == NULL ) ber_free_buf( ber );
+ send_ldap_error( op, rs, LDAP_OTHER, "encoding description error");
+ goto error_return;
+ }
+ }
if (( rc = ber_printf( ber, "O", &a->a_vals[i] )) == -1 ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
}
}
- if (( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
+ if ( finish && ( rc = ber_printf( ber, /*{[*/ "]N}" )) == -1 ) {
#ifdef NEW_LOGGING
LDAP_LOG( OPERATION, ERR,
"send_search_entry: conn %lu ber_printf failed\n",
* Reuse previous memory - we likely need less space
* for operational attributes
*/
- tmp = sl_realloc( e_flags, i * sizeof(char *) + k,
+ tmp = slap_sl_realloc( e_flags, i * sizeof(char *) + k,
op->o_tmpmemctx );
if ( tmp == NULL ) {
#ifdef NEW_LOGGING
/* free e_flags */
if ( e_flags ) {
- sl_free( e_flags, op->o_tmpmemctx );
+ slap_sl_free( e_flags, op->o_tmpmemctx );
e_flags = NULL;
}
rs->sr_flags &= ~REP_ENTRY_MUSTBEFREED;
}
- if ( e_flags ) sl_free( e_flags, op->o_tmpmemctx );
+ if ( e_flags ) slap_sl_free( e_flags, op->o_tmpmemctx );
if (op->o_callback) {
slap_callback *sc = op->o_callback;
c.ldctl_oid = oid->bv_val;
c.ldctl_iscritical = 0;
- *ctrl = sl_calloc( 1, sizeof(LDAPControl), NULL );
+ *ctrl = slap_sl_calloc( 1, sizeof(LDAPControl), NULL );
**ctrl = c;
return LDAP_SUCCESS;
}
+
+/* Map API errors to protocol errors... */
+int
+slap_map_api2result( SlapReply *rs )
+{
+ switch(rs->sr_err) {
+ case LDAP_SERVER_DOWN:
+ return LDAP_UNAVAILABLE;
+ case LDAP_LOCAL_ERROR:
+ return LDAP_OTHER;
+ case LDAP_ENCODING_ERROR:
+ case LDAP_DECODING_ERROR:
+ return LDAP_PROTOCOL_ERROR;
+ case LDAP_TIMEOUT:
+ return LDAP_UNAVAILABLE;
+ case LDAP_AUTH_UNKNOWN:
+ return LDAP_AUTH_METHOD_NOT_SUPPORTED;
+ case LDAP_FILTER_ERROR:
+ rs->sr_text = "Filter error";
+ return LDAP_OTHER;
+ case LDAP_USER_CANCELLED:
+ rs->sr_text = "User cancelled";
+ return LDAP_OTHER;
+ case LDAP_PARAM_ERROR:
+ return LDAP_PROTOCOL_ERROR;
+ case LDAP_NO_MEMORY:
+ return LDAP_OTHER;
+ case LDAP_CONNECT_ERROR:
+ return LDAP_UNAVAILABLE;
+ case LDAP_NOT_SUPPORTED:
+ return LDAP_UNWILLING_TO_PERFORM;
+ case LDAP_CONTROL_NOT_FOUND:
+ return LDAP_PROTOCOL_ERROR;
+ case LDAP_NO_RESULTS_RETURNED:
+ return LDAP_NO_SUCH_OBJECT;
+ case LDAP_MORE_RESULTS_TO_RETURN:
+ rs->sr_text = "More results to return";
+ return LDAP_OTHER;
+ case LDAP_CLIENT_LOOP:
+ case LDAP_REFERRAL_LIMIT_EXCEEDED:
+ return LDAP_LOOP_DETECT;
+ default:
+ if ( LDAP_API_ERROR(rs->sr_err) ) return LDAP_OTHER;
+ return rs->sr_err;
+ }
+}
+