]> git.sur5r.net Git - openldap/blobdiff - servers/slapd/syncrepl.c
Fix certificateListValidate parsing of CRL extensions
[openldap] / servers / slapd / syncrepl.c
index 39715f13a394323c1136e701a4c9e7c324b79c4d..627e43a3d2e5458d9f46fea7121e4e10ce2937de 100644 (file)
@@ -1256,7 +1256,7 @@ do_syncrepl(
        int rc = LDAP_SUCCESS;
        int dostop = 0;
        ber_socket_t s;
-       int i, defer = 1, fail = 0;
+       int i, defer = 1, fail = 0, freeinfo = 0;
        Backend *be;
 
        if ( si == NULL )
@@ -1274,8 +1274,9 @@ do_syncrepl(
                        ldap_pvt_thread_yield();
        }
 
-       if ( !si->si_ctype )
+       if ( si->si_ctype < 1 ) {
                goto deleted;
+       }
 
        switch( abs( si->si_type ) ) {
        case LDAP_SYNC_REFRESH_ONLY:
@@ -1362,7 +1363,11 @@ reload:
 
 deleted:
                /* We got deleted while running on cn=config */
-               if ( !si->si_ctype ) {
+               if ( si->si_ctype < 1 ) {
+                       if ( si->si_ctype == -1 ) {
+                               si->si_ctype = 0;
+                               freeinfo = 1;
+                       }
                        if ( si->si_conn )
                                dostop = 1;
                        rc = -1;
@@ -1429,7 +1434,7 @@ deleted:
                                break;
                }
 
-               if ( !si->si_ctype
+               if ( si->si_ctype < 1
                        || !si->si_retrynum || si->si_retrynum[i] == RETRYNUM_TAIL ) {
                        if ( si->si_re ) {
                                ldap_pvt_runqueue_remove( &slapd_rq, rtask );
@@ -1466,7 +1471,7 @@ deleted:
        }
 
        /* Do final delete cleanup */
-       if ( !si->si_ctype ) {
+       if ( freeinfo ) {
                syncinfo_free( si, 0 );
        }
        return NULL;
@@ -1622,7 +1627,16 @@ syncrepl_message_to_op(
 
                if ( !ber_bvstrcasecmp( &bv, &ls->ls_dn ) ) {
                        bdn = bvals[0];
-                       dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
+                       rc = dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
+                       if ( rc != LDAP_SUCCESS ) {
+                               Debug( LDAP_DEBUG_ANY,
+                                       "syncrepl_message_to_op: %s "
+                                       "dn \"%s\" normalization failed (%d)",
+                                       si->si_ridtxt, bdn.bv_val, rc );
+                               rc = -1;
+                               ch_free( bvals );
+                               goto done;
+                       }
                        ber_dupbv( &op->o_req_dn, &dn );
                        ber_dupbv( &op->o_req_ndn, &ndn );
                        slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
@@ -1854,7 +1868,21 @@ syncrepl_message_to_entry(
                return -1;
        }
 
-       dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
+       rc = dnPrettyNormal( NULL, &bdn, &dn, &ndn, op->o_tmpmemctx );
+       if ( rc != LDAP_SUCCESS ) {
+               /* One of the things that could happen is that the schema
+                * is not lined-up; this could result in unknown attributes.
+                * A value non conformant to the syntax should be unlikely,
+                * except when replicating between different versions
+                * of the software, or when syntax validation bugs are fixed
+                */
+               Debug( LDAP_DEBUG_ANY,
+                       "syncrepl_message_to_entry: "
+                       "%s dn \"%s\" normalization failed (%d)",
+                       si->si_ridtxt, bdn.bv_val, rc );
+               return rc;
+       }
+
        ber_dupbv( &op->o_req_dn, &dn );
        ber_dupbv( &op->o_req_ndn, &ndn );
        slap_sl_free( ndn.bv_val, op->o_tmpmemctx );
@@ -4304,6 +4332,8 @@ add_syncrepl(
        rc = parse_syncrepl_line( c, si );
 
        if ( rc == 0 ) {
+               LDAPURLDesc *lud;
+
                /* Must be LDAPv3 because we need controls */
                switch ( si->si_bindconf.sb_version ) {
                case 0:
@@ -4321,24 +4351,35 @@ add_syncrepl(
                        return 1;
                }
 
+               if ( ldap_url_parse( si->si_bindconf.sb_uri.bv_val, &lud )) {
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
+                               "<%s> invalid URL", c->argv[0] );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s %s\n",
+                               c->log, c->cr_msg, si->si_bindconf.sb_uri.bv_val );
+                       return 1;
+               }
+
                si->si_be = c->be;
                if ( slapMode & SLAP_SERVER_MODE ) {
-                       Listener **l = slapd_get_listeners();
                        int isMe = 0;
-
-                       /* check if URL points to current server. If so, ignore
-                        * this configuration. We require an exact match. Just
-                        * in case they really want to do this, they can vary
-                        * the case of the URL to allow it.
+                       /* check if consumer points to current server and database.
+                        * If so, ignore this configuration.
                         */
-                       if ( l && !SLAP_DBHIDDEN( c->be ) ) {
+                       if ( !SLAP_DBHIDDEN( c->be ) ) {
                                int i;
-                               for ( i=0; l[i]; i++ ) {
-                                       if ( bvmatch( &l[i]->sl_url, &si->si_bindconf.sb_uri ) ) {
+                               /* if searchbase doesn't match current DB suffix,
+                                * assume it's different
+                                */
+                               for ( i=0; !BER_BVISNULL( &c->be->be_nsuffix[i] ); i++ ) {
+                                       if ( bvmatch( &si->si_base, &c->be->be_nsuffix[i] )) {
                                                isMe = 1;
                                                break;
                                        }
                                }
+                               /* if searchbase matches, see if URLs match */
+                               if ( isMe && config_check_my_url( si->si_bindconf.sb_uri.bv_val,
+                                               lud ) == NULL )
+                                       isMe = 0;
                        }
 
                        if ( !isMe ) {
@@ -4357,6 +4398,7 @@ add_syncrepl(
                        /* mirrormode still needs to see this flag in tool mode */
                        rc = config_sync_shadow( c ) ? -1 : 0;
                }
+               ldap_free_urldesc( lud );
        }
 
 #ifdef HAVE_TLS
@@ -4603,27 +4645,19 @@ syncrepl_config( ConfigArgs *c )
                                                        isrunning = 1;
                                                } else {
                                                        if ( si->si_conn ) {
-                                                               isrunning = 1;
-                                                               /* If there's a persistent connection, we don't
-                                                                * know if it's already got a thread queued.
-                                                                * so defer the free, but reschedule the task.
-                                                                * If there's a connection thread queued, it
-                                                                * will cleanup as necessary. If not, then the
-                                                                * runqueue task will cleanup.
+                                                               /* If there's a persistent connection, it may
+                                                                * already have a thread queued. We know it's
+                                                                * not active, so it must be pending and we
+                                                                * can simply cancel it now.
                                                                 */
-                                                               ldap_pvt_thread_mutex_lock( &slapd_rq.rq_mutex );
-                                                               if ( !ldap_pvt_runqueue_isrunning( &slapd_rq, si->si_re )) {
-                                                                       si->si_re->interval.tv_sec = 0;
-                                                                       ldap_pvt_runqueue_resched( &slapd_rq, si->si_re, 0 );
-                                                                       si->si_re->interval.tv_sec = si->si_interval;
-                                                               }
-                                                               ldap_pvt_thread_mutex_unlock( &slapd_rq.rq_mutex );
+                                                               ldap_pvt_thread_pool_retract( &connection_pool,
+                                                                       si->si_re->routine, si->si_re );
                                                        }
                                                        ldap_pvt_thread_mutex_unlock( &si->si_mutex );
                                                }
                                        }
                                        if ( isrunning ) {
-                                               si->si_ctype = 0;
+                                               si->si_ctype = -1;
                                                si->si_next = NULL;
                                        } else {
                                                syncinfo_free( si, 0 );