~ubuntu-branches/ubuntu/oneiric/openldap/oneiric

« back to all changes in this revision

Viewing changes to libraries/libldap/ldap_sync.c

  • Committer: Bazaar Package Importer
  • Author(s): Chuck Short
  • Date: 2011-05-08 16:34:09 UTC
  • mfrom: (1.1.8 upstream) (0.3.11 sid)
  • Revision ID: james.westby@ubuntu.com-20110508163409-yjop2tgwy54fi0tm
Tags: 2.4.25-1ubuntu1
* Merge from debian unstable.  Remaining changes:
  - Install a default DIT (LP: #442498).
  - Document cn=config in README file (LP: #370784).
  - remaining changes:
    + AppArmor support:
      - debian/apparmor-profile: add AppArmor profile
      - use dh_apparmor:
        - debian/rules: use dh_apparmor
        - debian/control: Build-Depends on debhelper 7.4.20ubuntu5
      - updated debian/slapd.README.Debian for note on AppArmor
      - debian/slapd.dirs: add etc/apparmor.d/force-complain
    + Enable GSSAPI support (LP: #495418):
      - debian/patches/gssapi.diff, thanks to Jerry Carter (Likewise):
        - Add --with-gssapi support
        - Make guess_service_principal() more robust when determining
          principal
      - debian/patches/series: apply gssapi.diff patch.
      - debian/configure.options: Configure with --with-gssapi
      - debian/control: Added libkrb5-dev as a build depend
    + debian/rules: Enable -DLDAP_CONNECTIONLESS to build CLDAP (UDP) support
      in the openldap library, as required by Likewise-Open (LP: #390579)
    + Don't build smbk5pwd overlay since it uses heimdal instead of krb5:
      - debian/control: 
        - remove build-dependency on heimdal-dev.
        - remove slapd-smbk5pwd binary package.
      - debian/rules: don't build smbk5pwd slapd module.
    + debian/{control,rules}: enable PIE hardening
    + ufw support (LP: #423246):
      - debian/control: suggest ufw.
      - debian/rules: install ufw profile.
      - debian/slapd.ufw.profile: add ufw profile.
    + Enable nssoverlay:
      - debian/patches/nssov-build, debian/series, debian/rules: 
        Apply, build and package the nss overlay.
      - debian/schema/extra/misc.ldif: add ldif file for the misc schema
        which defines rfc822MailMember (required by the nss overlay).
    + debian/rules, debian/schema/extra/: 
      Fix configure rule to supports extra schemas shipped as part
      of the debian/schema/ directory.
    + debian/rules, debian/slapd.py: Add apport hook. (LP: #610544)
    + debian/slapd.init.ldif: don't set olcRootDN since it's not defined in
      neither the default DIT nor via an Authn mapping.
    + debian/slapd.scripts-common: adjust minimum version that triggers a
      database upgrade. Upgrade from maverick shouldn't trigger database
      upgrade (which would happen with the version used in Debian).
    + debian/slapd.scripts-common: add slapcat_opts to local variables.
      Remove unused variable new_conf.
    + debian/slapd.script-common: Fix package reconfiguration.
      - Fix backup directory naming for multiple reconfiguration.
    + debian/slapd.default, debian/slapd.README.Debian: 
      use the new configuration style.
    + Install nss overlay (LP: #675391):
      - debian/rules: run install target for nssov module.
      - debian/patches/nssov-build: fix patch to install schema in /etc/ldap/schema
    + debian/patches/gssapi.diff:
      - Update patch so that likewise-open is usuable again. (LP: #661547)
    + debian/patches/service-operational-before-detach: New patch replacing old one
      of the same name as previous could cause database corruption based on upstream commits.
      (LP: #727973)
     + Dropped:
       - debian/patches/gold: Use the debian version instead
       - debian/patches/CVE-2011-1024: Fixed upstream
       - debian/patches/CVE-2011-1025: Fixed upstream
       - debian/patches/CVE-2011-1081: Fixed upstream 

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $OpenLDAP: pkg/ldap/libraries/libldap/ldap_sync.c,v 1.2.2.6 2010/04/13 20:22:58 kurt Exp $ */
 
1
/* $OpenLDAP: pkg/ldap/libraries/libldap/ldap_sync.c,v 1.2.2.8 2011/01/26 19:00:40 quanah Exp $ */
2
2
/* This work is part of OpenLDAP Software <http://www.openldap.org/>.
3
3
 *
4
 
 * Copyright 2006-2010 The OpenLDAP Foundation.
 
4
 * Copyright 2006-2011 The OpenLDAP Foundation.
5
5
 * All rights reserved.
6
6
 *
7
7
 * Redistribution and use in source and binary forms, with or without
128
128
ldap_sync_search_entry( ldap_sync_t *ls, LDAPMessage *res )
129
129
{
130
130
        LDAPControl             **ctrls = NULL;
131
 
        int                     rc = LDAP_SUCCESS,
 
131
        int                     rc = LDAP_OTHER,
132
132
                                i;
133
133
        BerElement              *ber = NULL;
134
134
        struct berval           entryUUID = { 0 },
159
159
        /* extract controls */
160
160
        ldap_get_entry_controls( ls->ls_ld, res, &ctrls );
161
161
        if ( ctrls == NULL ) {
162
 
                rc = LDAP_OTHER;
163
162
                goto done;
164
163
        }
165
164
 
172
171
 
173
172
        /* control must be present; there might be other... */
174
173
        if ( ctrls[ i ] == NULL ) {
175
 
                rc = LDAP_OTHER;
176
174
                goto done;
177
175
        }
178
176
 
179
177
        /* extract data */
180
178
        ber = ber_init( &ctrls[ i ]->ldctl_value );
 
179
        if ( ber == NULL ) {
 
180
                goto done;
 
181
        }
181
182
        /* scan entryUUID in-place ("m") */
182
 
        ber_scanf( ber, "{em" /*"}"*/, &state, &entryUUID );
183
 
        if ( entryUUID.bv_len == 0 ) {
184
 
                rc = LDAP_OTHER;
 
183
        if ( ber_scanf( ber, "{em" /*"}"*/, &state, &entryUUID ) == LBER_ERROR
 
184
                || entryUUID.bv_len == 0 )
 
185
        {
185
186
                goto done;
186
187
        }
187
188
 
188
189
        if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
189
190
                /* scan cookie in-place ("m") */
190
 
                ber_scanf( ber, /*"{"*/ "m}", &cookie );
 
191
                if ( ber_scanf( ber, /*"{"*/ "m}", &cookie ) == LBER_ERROR ) {
 
192
                        goto done;
 
193
                }
191
194
                if ( cookie.bv_val != NULL ) {
192
195
                        ber_bvreplace( &ls->ls_cookie, &cookie );
193
196
                }
212
215
                break;
213
216
 
214
217
        default:
215
 
                rc = LDAP_OTHER;
216
218
#ifdef LDAP_SYNC_TRACE
217
219
                fprintf( stderr, "\t\tgot unknown syncState=%d\n", state );
218
220
#endif /* LDAP_SYNC_TRACE */
219
221
                goto done;
220
222
        }
221
223
 
222
 
        if ( ls->ls_search_entry ) {
223
 
                rc = ls->ls_search_entry( ls, res, &entryUUID, phase );
224
 
        }
 
224
        rc = ls->ls_search_entry
 
225
                ? ls->ls_search_entry( ls, res, &entryUUID, phase )
 
226
                : LDAP_SUCCESS;
225
227
 
226
228
done:;
227
229
        if ( ber != NULL ) {
302
304
                ber_len_t       len;
303
305
                struct berval   cookie = { 0 };
304
306
 
 
307
                rc = LDAP_OTHER;
 
308
 
305
309
                /* deal with control; then fallthru to handler */
306
310
                if ( ctrls == NULL ) {
307
 
                        rc = LDAP_OTHER;
308
311
                        goto done;
309
312
                }
310
313
 
319
322
 
320
323
                /* control must be present; there might be other... */
321
324
                if ( ctrls[ i ] == NULL ) {
322
 
                        rc = LDAP_OTHER;
323
325
                        goto done;
324
326
                }
325
327
 
326
328
                /* extract data */
327
329
                ber = ber_init( &ctrls[ i ]->ldctl_value );
 
330
                if ( ber == NULL ) {
 
331
                        goto done;
 
332
                }
328
333
 
329
 
                ber_scanf( ber, "{" /*"}"*/);
 
334
                if ( ber_scanf( ber, "{" /*"}"*/) == LBER_ERROR ) {
 
335
                        goto ber_done;
 
336
                }
330
337
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
331
 
                        ber_scanf( ber, "m", &cookie );
 
338
                        if ( ber_scanf( ber, "m", &cookie ) == LBER_ERROR ) {
 
339
                                goto ber_done;
 
340
                        }
332
341
                        if ( cookie.bv_val != NULL ) {
333
342
                                ber_bvreplace( &ls->ls_cookie, &cookie );
334
343
                        }
340
349
 
341
350
                refreshDeletes = 0;
342
351
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES ) {
343
 
                        ber_scanf( ber, "b", &refreshDeletes );
 
352
                        if ( ber_scanf( ber, "b", &refreshDeletes ) == LBER_ERROR ) {
 
353
                                goto ber_done;
 
354
                        }
344
355
                        if ( refreshDeletes ) {
345
356
                                refreshDeletes = 1;
346
357
                        }
347
358
                }
348
359
 
349
 
                ber_scanf( ber, /*"{"*/ "}" );
 
360
                if ( ber_scanf( ber, /*"{"*/ "}" ) != LBER_ERROR ) {
 
361
                        rc = LDAP_SUCCESS;
 
362
                }
350
363
 
351
 
                /* NOTE: if any goto/return between ber_init() and here
352
 
                 * is introduced, don't forget to ber_free() */
 
364
        ber_done:;
353
365
                ber_free( ber, 1 );
 
366
                if ( rc != LDAP_SUCCESS ) {
 
367
                        break;
 
368
                }
354
369
 
355
370
#ifdef LDAP_SYNC_TRACE
356
371
                fprintf( stderr, "\t\tgot refreshDeletes=%s\n",
379
394
                        err = ls->ls_search_result( ls, res, refreshDeletes );
380
395
                }
381
396
                break;
382
 
 
383
 
        default:
384
 
                break;
385
397
        }
386
398
 
387
399
done:;
413
425
        struct berval           *retdata = NULL;
414
426
        BerElement              *ber = NULL;
415
427
        ber_len_t               len;
416
 
        ber_tag_t               tag,
417
 
                                syncinfo_tag;
 
428
        ber_tag_t               syncinfo_tag;
418
429
        struct berval           cookie;
419
430
        int                     refreshDeletes = 0;
420
431
        BerVarray               syncUUIDs = NULL;
444
455
                goto done;
445
456
        }
446
457
 
 
458
        rc = LDAP_OTHER;
 
459
 
447
460
        if ( retoid == NULL || strcmp( retoid, LDAP_SYNC_INFO ) != 0 ) {
448
 
                rc = LDAP_OTHER;
449
461
                goto done;
450
462
        }
451
463
 
458
470
        syncinfo_tag = ber_peek_tag( ber, &len );
459
471
        switch ( syncinfo_tag ) {
460
472
        case LDAP_TAG_SYNC_NEW_COOKIE:
461
 
                ber_scanf( ber, "tm", &tag, &cookie );
 
473
                if ( ber_scanf( ber, "m", &cookie ) == LBER_ERROR ) {
 
474
                        goto done;
 
475
                }
462
476
                if ( cookie.bv_val != NULL ) {
463
477
                        ber_bvreplace( &ls->ls_cookie, &cookie );
464
478
                }
482
496
 
483
497
                        default:
484
498
                                /* TODO: impossible; handle */
485
 
                                rc = LDAP_OTHER;
486
499
                                goto done;
487
500
                        }
488
501
 
497
510
 
498
511
                        default:
499
512
                                /* TODO: impossible; handle */
500
 
                                rc = LDAP_OTHER;
501
513
                                goto done;
502
514
                        }
503
515
                }
504
516
 
505
 
                ber_scanf( ber, "t{" /*"}"*/, &tag );
 
517
                if ( ber_scanf( ber, "{" /*"}"*/ ) == LBER_ERROR ) {
 
518
                        goto done;
 
519
                }
506
520
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
507
 
                        ber_scanf( ber, "m", &cookie );
 
521
                        if ( ber_scanf( ber, "m", &cookie ) == LBER_ERROR ) {
 
522
                                goto done;
 
523
                        }
508
524
                        if ( cookie.bv_val != NULL ) {
509
525
                                ber_bvreplace( &ls->ls_cookie, &cookie );
510
526
                        }
516
532
 
517
533
                *refreshDone = 1;
518
534
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDONE ) {
519
 
                        ber_scanf( ber, "b", refreshDone );
 
535
                        if ( ber_scanf( ber, "b", refreshDone ) == LBER_ERROR ) {
 
536
                                goto done;
 
537
                        }
520
538
                }
521
539
 
522
540
#ifdef LDAP_SYNC_TRACE
524
542
                        *refreshDone ? "TRUE" : "FALSE" );
525
543
#endif /* LDAP_SYNC_TRACE */
526
544
 
527
 
                ber_scanf( ber, /*"{"*/ "}" );
 
545
                if ( ber_scanf( ber, /*"{"*/ "}" ) == LBER_ERROR ) {
 
546
                        goto done;
 
547
                }
528
548
 
529
549
                if ( *refreshDone ) {
530
550
                        ls->ls_refreshPhase = LDAP_SYNC_CAPI_DONE;
540
560
#ifdef LDAP_SYNC_TRACE
541
561
                fprintf( stderr, "\t\tgot syncIdSet\n" );
542
562
#endif /* LDAP_SYNC_TRACE */
543
 
                ber_scanf( ber, "t{" /*"}"*/, &tag );
 
563
                if ( ber_scanf( ber, "{" /*"}"*/ ) == LBER_ERROR ) {
 
564
                        goto done;
 
565
                }
544
566
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_SYNC_COOKIE ) {
545
 
                        ber_scanf( ber, "m", &cookie );
 
567
                        if ( ber_scanf( ber, "m", &cookie ) == LBER_ERROR ) {
 
568
                                goto done;
 
569
                        }
546
570
                        if ( cookie.bv_val != NULL ) {
547
571
                                ber_bvreplace( &ls->ls_cookie, &cookie );
548
572
                        }
553
577
                }
554
578
 
555
579
                if ( ber_peek_tag( ber, &len ) == LDAP_TAG_REFRESHDELETES ) {
556
 
                        ber_scanf( ber, "b", &refreshDeletes );
 
580
                        if ( ber_scanf( ber, "b", &refreshDeletes ) == LBER_ERROR ) {
 
581
                                goto done;
 
582
                        }
557
583
                }
558
584
 
559
 
                ber_scanf( ber, "[W]", &syncUUIDs );
560
 
                ber_scanf( ber, /*"{"*/ "}" );
561
 
                if ( syncUUIDs == NULL ) {
562
 
                        rc = LDAP_OTHER;
 
585
                if ( ber_scanf( ber, /*"{"*/ "[W]}", &syncUUIDs ) == LBER_ERROR
 
586
                        || syncUUIDs == NULL )
 
587
                {
563
588
                        goto done;
564
589
                }
565
590
 
601
626
                goto done;
602
627
        }
603
628
 
 
629
        rc = LDAP_SUCCESS;
 
630
 
604
631
done:;
605
632
        if ( ber != NULL ) {
606
633
                ber_free( ber, 1 );
899
926
done:;
900
927
        return rc;
901
928
}
902