~ubuntu-branches/ubuntu/maverick/openldap/maverick-proposed

« back to all changes in this revision

Viewing changes to servers/slapd/result.c

  • Committer: Bazaar Package Importer
  • Author(s): Mathias Gug, Steve Langasek, Mathias Gug
  • Date: 2009-02-18 18:44:00 UTC
  • mfrom: (1.1.2 upstream) (0.1.2 lenny)
  • Revision ID: james.westby@ubuntu.com-20090218184400-zw4mjse9eywt5566
Tags: 2.4.14-0ubuntu1
[ Steve Langasek ]
* New upstream version
  - Fixes a bug with the pcache overlay not returning cached entries
    (closes: #497697)
  - Update evolution-ntlm patch to apply to current Makefiles.
  - (tentatively) drop gnutls-ciphers, since this bug was reported to be
    fixed upstream in 2.4.8.  The fix applied in 2.4.8 didn't match the
    patch from the bug report, so this should be watched for regressions.
* Build against db4.7 instead of db4.2 at last!  Closes: #421946.
* Build with --disable-ndb, to avoid a misbuild when libmysqlclient is
  installed in the build environment.
* New patch, no-crlcheck-for-gnutls, to fix a build failure when using
  --with-tls=gnutls.

[ Mathias Gug ]
* Merge from debian unstable, remaining changes:
  - debian/apparmor-profile: add AppArmor profile
  - debian/slapd.postinst: Reload AA profile on configuration
  - updated debian/slapd.README.Debian for note on AppArmor
  - debian/control: Recommends apparmor >= 2.1+1075-0ubuntu6
  - debian/control: Conflicts with apparmor-profiles << 2.1+1075-0ubuntu4
    to make sure that if earlier version of apparmour-profiles gets
    installed it won't overwrite our profile.
  - Modify Maintainer value to match the DebianMaintainerField
    speficication.
  - follow ApparmorProfileMigration and force apparmor compalin mode on 
    some upgrades (LP: #203529)
  - debian/slapd.dirs: add etc/apparmor.d/force-complain
  - debian/slapd.preinst: create symlink for force-complain on pre-feisty
    upgrades, upgrades where apparmor-profiles profile is unchanged (ie
    non-enforcing) and upgrades where apparmor profile does not exist.
  - debian/slapd.postrm: remove symlink in force-complain/ on purge
  - debian/patches/fix-ucred-libc due to changes how newer glibc handle
    the ucred struct now.
  - debian/control:
    - Build-depend on libltdl7-dev rather then libltdl3-dev.
  - debian/patches/autogen.sh:
    - Call libtoolize with the --install option to install config.{guess,sub}
      files.
  - Don't use local statement in config script as it fails if /bin/sh
    points to bash (LP: #286063).
  - Disable the testsuite on hppa. Allows building of packages on this
    architecture again, once this package is in the archive.
    LP: #288908.
  - debian/slapd.postinst, debian/slapd.script-common: set correct ownership
    and permissions on /var/lib/ldap, /etc/ldap/slapd.d (group readable) and
    /var/run/slapd (world readable). (LP: #257667).
  - debian/patches/nssov-build, debian/rules: 
    Build and package the nss overlay.
    debian/schema/misc.ldif: add ldif file for the misc schema, which defines
    rfc822MailMember (required by the nss overlay).
  - debian/{control,rules}: enable PIE hardening
  - Use cn=config as the default configuration backend instead of 
    slapd.conf. Migrate slapd.conf  file to /etc/ldap/slapd.d/ on upgrade
    asking the end user to enter a new password to control the access to the
    cn=config tree.
* debian/patches/corrupt-contextCSN: The contextCSN can get corrupted at
  times. (ITS: #5947)

Show diffs side-by-side

added added

removed removed

Lines of Context:
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/>.
4
4
 *
5
 
 * Copyright 1998-2008 The OpenLDAP Foundation.
 
5
 * Copyright 1998-2009 The OpenLDAP Foundation.
6
6
 * All rights reserved.
7
7
 *
8
8
 * Redistribution and use in source and binary forms, with or without
137
137
        BerElement *ber )
138
138
{
139
139
        ber_len_t bytes;
 
140
        long ret = 0;
 
141
        int closing = 0;
140
142
 
141
143
        ber_get_option( ber, LBER_OPT_BER_BYTES_TO_WRITE, &bytes );
142
144
 
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 );
145
 
 
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 );
 
149
                return 0;
 
150
        }
 
151
        while ( conn->c_writers > 0 ) {
 
152
                ldap_pvt_thread_cond_wait( &conn->c_write1_cv, &conn->c_write1_mutex );
 
153
        }
 
154
        /* connection was closed under us */
 
155
        if ( conn->c_writers < 0 ) {
 
156
                closing = 1;
 
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 );
 
160
        }
 
161
 
 
162
        conn->c_writers++;
 
163
 
 
164
        if ( closing ) {
 
165
                ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
 
166
                return 0;
 
167
        }
148
168
 
149
169
        /* write the pdu */
150
170
        while( 1 ) {
151
171
                int err;
152
172
 
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 );
156
 
 
157
 
                        return 0;
 
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 ) {
 
178
                                ret = 0;
 
179
                                break;
 
180
                        }
 
181
                        continue;
158
182
                }
159
183
 
160
184
                if ( ber_flush2( conn->c_sb, ber, LBER_FLUSH_FREE_NEVER ) == 0 ) {
 
185
                        ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
 
186
                        ret = bytes;
161
187
                        break;
162
188
                }
163
189
 
173
199
                    err, sock_errstr(err), 0 );
174
200
 
175
201
                if ( err != EWOULDBLOCK && err != EAGAIN ) {
 
202
                        conn->c_writers--;
 
203
                        ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
176
204
                        connection_closing( conn, "connection lost on write" );
177
205
 
178
206
                        ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
179
 
                        ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
180
 
 
181
 
                        return( -1 );
 
207
                        return -1;
182
208
                }
183
209
 
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 );
187
214
 
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;
190
 
        }
191
 
 
192
 
        ldap_pvt_thread_mutex_unlock( &conn->c_mutex );
193
 
        ldap_pvt_thread_mutex_unlock( &conn->c_write_mutex );
194
 
 
195
 
        return bytes;
 
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 ) {
 
222
                        ret = 0;
 
223
                        break;
 
224
                }
 
225
        }
 
226
 
 
227
        if ( conn->c_writers < 0 ) {
 
228
                conn->c_writers++;
 
229
                if ( !conn->c_writers )
 
230
                        ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
 
231
        } else {
 
232
                conn->c_writers--;
 
233
                ldap_pvt_thread_cond_signal( &conn->c_write1_cv );
 
234
        }
 
235
        ldap_pvt_thread_mutex_unlock( &conn->c_write1_mutex );
 
236
 
 
237
        return ret;
196
238
}
197
239
 
198
240
static int
538
580
                }
539
581
        }
540
582
 
 
583
        if ( rs->sr_flags & REP_CTRLS_MUSTBEFREED ) {
 
584
                rs->sr_flags ^= REP_CTRLS_MUSTBEFREED; /* paranoia */
 
585
                if ( rs->sr_ctrls ) {
 
586
                        slap_free_ctrls( op, rs->sr_ctrls );
 
587
                        rs->sr_ctrls = NULL;
 
588
                }
 
589
        }
 
590
 
541
591
        return rc;
542
592
}
543
593
 
641
691
 
642
692
        if ( send_ldap_response( op, rs ) == SLAP_CB_CONTINUE ) {
643
693
                if ( op->o_tag == LDAP_REQ_SEARCH ) {
644
 
                        char nbuf[64];
645
 
                        snprintf( nbuf, sizeof nbuf, "%d nentries=%d",
646
 
                                rs->sr_err, rs->sr_nentries );
647
 
 
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 : "" );
652
698
                } else {
653
699
                        Statslog( LDAP_DEBUG_STATS,
654
700
                                "%s RESULT tag=%lu err=%d text=%s\n",
739
785
        BerElement      *ber = (BerElement *) &berbuf;
740
786
        Attribute       *a;
741
787
        int             i, j, rc = LDAP_UNAVAILABLE, bytes;
742
 
        char            *edn;
743
788
        int             userattrs;
744
789
        AccessControlState acl_state = ACL_STATE_INIT;
745
790
        int                      attrsonly;
802
847
                goto error_return;
803
848
        }
804
849
 
805
 
        edn = rs->sr_entry->e_nname.bv_val;
806
 
 
807
850
        if ( op->o_res_ber ) {
808
851
                /* read back control or LDAP_CONNECTIONLESS */
809
852
            ber = op->o_res_ber;
1190
1233
                goto error_return;
1191
1234
        }
1192
1235
 
 
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 );
 
1238
 
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 );
1218
1264
        }
1219
1265
 
1220
 
        Statslog( LDAP_DEBUG_STATS2, "%s ENTRY dn=\"%s\"\n",
1221
 
            op->o_log_prefix, edn, 0, 0, 0 );
1222
 
 
1223
1266
        Debug( LDAP_DEBUG_TRACE,
1224
1267
                "<= send_search_entry: conn %lu exit.\n", op->o_connid, 0, 0 );
1225
1268
 
1265
1308
        BerElement      *ber = (BerElement *) &berbuf;
1266
1309
        int rc = 0;
1267
1310
        int bytes;
 
1311
        char *edn = rs->sr_entry ? rs->sr_entry->e_name.bv_val : "(null)";
1268
1312
 
1269
1313
        AttributeDescription *ad_ref = slap_schema.si_ad_ref;
1270
1314
        AttributeDescription *ad_entry = slap_schema.si_ad_entry;
1279
1323
 
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 );
 
1326
                edn, 0, 0 );
1283
1327
 
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 );
 
1352
                        edn, 0, 0 );
1309
1353
                rc = 0;
1310
1354
                goto rel;
1311
1355
        }
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 );
 
1360
                        edn, 0, 0 );
1317
1361
                rc = 1;
1318
1362
                goto rel;
1319
1363
        }
1363
1407
 
1364
1408
        rc = 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;
1512
1557
        LDAPControl c;
1513
1558
        Operation myop;
1514
1559
 
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 );
1517
1562
 
1518
1563
        rs->sr_entry = e;
1519
1564
        rs->sr_attrs = ( oid == &slap_pre_read_bv ) ?
1538
1583
 
1539
1584
        rc = ber_flatten2( ber, &c.ldctl_value, 0 );
1540
1585
 
1541
 
        if( rc == LBER_ERROR ) return LDAP_OTHER;
 
1586
        if( rc == -1 ) return LDAP_OTHER;
1542
1587
 
1543
1588
        c.ldctl_oid = oid->bv_val;
1544
1589
        c.ldctl_iscritical = 0;