1
1
/* result.c - routines to send ldap results, errors, and referrals */
2
/* $OpenLDAP: pkg/ldap/servers/slapd/result.c,v 1.289.2.14 2008/05/28 16:28:18 quanah Exp $ */
2
/* $OpenLDAP: pkg/ldap/servers/slapd/result.c,v 1.289.2.21 2009/01/26 20:48:05 quanah Exp $ */
3
3
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
5
* Copyright 1998-2008 The OpenLDAP Foundation.
5
* Copyright 1998-2009 The OpenLDAP Foundation.
6
6
* All rights reserved.
8
8
* Redistribution and use in source and binary forms, with or without
137
137
BerElement *ber )
141
143
ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
143
145
/* write only one pdu at a time - wait til it's our turn */
144
ldap_pvt_thread_mutex_lock( &conn->c_write_mutex );
146
/* lock the connection */
147
ldap_pvt_thread_mutex_lock( &conn->c_mutex );
146
ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
147
if ( connection_state_closing( conn )) {
148
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
151
while ( conn->c_writers > 0 ) {
152
ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
154
/* connection was closed under us */
155
if ( conn->c_writers < 0 ) {
157
/* we're the last waiter, let the closer continue */
158
if ( conn->c_writers == -1 )
159
ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
165
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
149
169
/* write the pdu */
153
if ( connection_state_closing( conn ) ) {
154
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
155
ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
173
/* lock the connection */
174
if ( ldap_pvt_thread_mutex_trylock( &conn->c_mutex )) {
175
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
176
ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
177
if ( conn->c_writers < 0 ) {
160
184
if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
185
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
173
199
err, sock_errstr(err), 0 );
175
201
if ( err != EWOULDBLOCK && err != EAGAIN ) {
203
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
176
204
connection_closing( conn, "connection lost on write" );
178
206
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
179
ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
184
210
/* wait for socket to be write-ready */
211
ldap_pvt_thread_mutex_lock( &conn->c_write2_mutex );
185
212
conn->c_writewaiter = 1;
186
213
slapd_set_write( conn->c_sd, 1 );
188
ldap_pvt_thread_cond_wait( &conn->c_write_cv, &conn->c_mutex );
215
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
216
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
217
ldap_pvt_thread_cond_wait( &conn->c_write2_cv, &conn->c_write2_mutex );
189
218
conn->c_writewaiter = 0;
192
ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
193
ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
219
ldap_pvt_thread_mutex_unlock( &conn->c_write2_mutex );
220
ldap_pvt_thread_mutex_lock( &conn->c_write1_mutex );
221
if ( conn->c_writers < 0 ) {
227
if ( conn->c_writers < 0 ) {
229
if ( !conn->c_writers )
230
ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
233
ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
235
ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
642
692
if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
643
693
if ( op->o_tag == LDAP_REQ_SEARCH ) {
645
snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
646
rs->sr_err, rs->sr_nentries );
648
694
Statslog( LDAP_DEBUG_STATS,
649
"%s SEARCH RESULT tag=%lu err=%s text=%s\n",
650
op->o_log_prefix, rs->sr_tag, nbuf,
651
rs->sr_text ? rs->sr_text : "", 0 );
695
"%s SEARCH RESULT tag=%lu err=%d nentries=%d text=%s\n",
696
op->o_log_prefix, rs->sr_tag, rs->sr_err,
697
rs->sr_nentries, rs->sr_text ? rs->sr_text : "" );
653
699
Statslog( LDAP_DEBUG_STATS,
654
700
"%s RESULT tag=%lu err=%d text=%s\n",
739
785
BerElement *ber = (BerElement *) &berbuf;
741
787
int i, j, rc = LDAP_UNAVAILABLE, bytes;
744
789
AccessControlState acl_state = ACL_STATE_INIT;
1190
1233
goto error_return;
1236
Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1237
op->o_log_prefix, rs->sr_entry->e_nname.bv_val, 0, 0, 0 );
1193
1239
if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1194
1240
be_entry_release_rw( op, rs->sr_entry, 0 );
1195
1241
rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1217
1263
ldap_pvt_thread_mutex_unlock( &op->o_counters->sc_mutex );
1220
Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1221
op->o_log_prefix, edn, 0, 0, 0 );
1223
1266
Debug( LDAP_DEBUG_TRACE,
1224
1267
"<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1265
1308
BerElement *ber = (BerElement *) &berbuf;
1311
char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
1269
1313
AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1270
1314
AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1280
1324
Debug( LDAP_DEBUG_TRACE,
1281
1325
"=> send_search_reference: dn=\"%s\"\n",
1282
rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)", 0, 0 );
1284
1328
if ( rs->sr_entry && ! access_allowed( op, rs->sr_entry,
1285
1329
ad_entry, NULL, ACL_READ, NULL ) )
1305
1349
if( op->o_domain_scope ) {
1306
1350
Debug( LDAP_DEBUG_ANY,
1307
1351
"send_search_reference: domainScope control in (%s)\n",
1308
rs->sr_entry->e_dn, 0, 0 );
1313
1357
if( rs->sr_ref == NULL ) {
1314
1358
Debug( LDAP_DEBUG_ANY,
1315
1359
"send_search_reference: null ref in (%s)\n",
1316
rs->sr_entry ? rs->sr_entry->e_dn : "(null)", 0, 0 );
1365
1409
if ( rs->sr_flags & REP_ENTRY_MUSTRELEASE ) {
1410
assert( rs->sr_entry != NULL );
1366
1411
be_entry_release_rw( op, rs->sr_entry, 0 );
1367
1412
rs->sr_flags ^= REP_ENTRY_MUSTRELEASE;
1368
1413
rs->sr_entry = NULL;
1513
1558
Operation myop;
1515
Debug( LDAP_DEBUG_ANY, "slap_read_controls: (%s) %s\n",
1516
oid->bv_val, e->e_dn, 0 );
1560
Debug( LDAP_DEBUG_ANY, "%s slap_read_controls: (%s) %s\n",
1561
op->o_log_prefix, oid->bv_val, e->e_dn );
1518
1563
rs->sr_entry = e;
1519
1564
rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1539
1584
rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1541
if( rc == LBER_ERROR ) return LDAP_OTHER;
1586
if( rc == -1 ) return LDAP_OTHER;
1543
1588
c.ldctl_oid = oid->bv_val;
1544
1589
c.ldctl_iscritical = 0;