]> git.ipfire.org Git - thirdparty/openldap.git/commitdiff
ITS#10197 Back-meta and back-asyncmeta add a new target structure and increase the...
authorNadezhda Ivanova <nivanova@symas.com>
Thu, 11 Apr 2024 11:10:07 +0000 (14:10 +0300)
committerQuanah Gibson-Mount <quanah@openldap.org>
Tue, 7 May 2024 16:31:45 +0000 (16:31 +0000)
Reproducible when adding a new target via cn=config

servers/slapd/back-asyncmeta/back-asyncmeta.h
servers/slapd/back-asyncmeta/config.c
servers/slapd/back-asyncmeta/init.c
servers/slapd/back-meta/back-meta.h
servers/slapd/back-meta/config.c
servers/slapd/back-meta/init.c

index 01d453be280e3f8db50823921da14691623ab4c8..038d2fa90ab25876dec883d2b20a41869ff1c587 100644 (file)
@@ -777,6 +777,9 @@ asyncmeta_db_has_pending_ops(a_metainfo_t *mi);
 int
 asyncmeta_db_has_mscs(a_metainfo_t *mi);
 
+void
+asyncmeta_target_free(a_metatarget_t *mt);
+
 /* The the maximum time in seconds after a result has been received on a connection,
  * after which it can be reset if a sender error occurs. Should this be configurable? */
 #define META_BACK_RESULT_INTERVAL (2)
index aae054ab0a318462555fbebaa950e8180edb111b..9271ba86a342a2e68cf8c60a5425d2a3ae5ab64c 100644 (file)
@@ -496,19 +496,14 @@ asyncmeta_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *c )
 
 static int
 asyncmeta_back_new_target(
-       a_metatarget_t  **mtp,
+       a_metatarget_t  *mt,
        a_metainfo_t     *mi,
        BackendDB        *db )
 {
-       a_metatarget_t          *mt;
-
-       *mtp = NULL;
        int i;
 
        assert ( mi != NULL );
-       mt = ch_calloc( sizeof( a_metatarget_t ), 1 );
-
-       ldap_pvt_thread_mutex_init( &mt->mt_uri_mutex );
+       assert ( mt != NULL );
 
        mt->mt_idassert_mode = LDAP_BACK_IDASSERT_LEGACY;
        mt->mt_idassert_authmethod = LDAP_AUTH_NONE;
@@ -516,7 +511,6 @@ asyncmeta_back_new_target(
        /* by default, use proxyAuthz control on each operation */
        mt->mt_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
 
-       *mtp = mt;
        if ( !SLAP_DBOPEN(db) || !(slapMode & SLAP_SERVER_MODE)) {
                return 0;
        }
@@ -1887,7 +1881,6 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                LDAPURLDesc     *ludp;
                struct berval   dn;
                int             j;
-
                char            **uris = NULL;
 
                if ( c->be->be_nsuffix == NULL ) {
@@ -1897,39 +1890,6 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                        return 1;
                }
 
-               i = mi->mi_ntargets++;
-
-               mi->mi_targets = ( a_metatarget_t ** )ch_realloc( mi->mi_targets,
-                       sizeof( a_metatarget_t * ) * mi->mi_ntargets );
-               if ( mi->mi_targets == NULL ) {
-                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
-                               "out of memory while storing server name"
-                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
-                               c->argv[0] );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
-                       return 1;
-               }
-
-               if ( asyncmeta_back_new_target( &mi->mi_targets[ i ], mi, c->be ) != 0 ) {
-                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
-                               "unable to init server"
-                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
-                               c->argv[0] );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
-                       return 1;
-               }
-
-               mt = mi->mi_targets[ i ];
-
-               mt->mt_rebind_f = mi->mi_rebind_f;
-               mt->mt_urllist_f = mi->mi_urllist_f;
-               mt->mt_urllist_p = mt;
-
-               if ( META_BACK_QUARANTINE( mi ) ) {
-                       ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
-               }
-               mt->mt_mc = mi->mi_mc;
-
                for ( j = 1; j < c->argc; j++ ) {
                        char    **tmpuris = ldap_str2charray( c->argv[ j ], "\t" );
 
@@ -1951,6 +1911,8 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                        }
                }
 
+               mt = ch_calloc( sizeof( a_metatarget_t ), 1 );
+
                for ( j = 0; uris[ j ] != NULL; j++ ) {
                        char *tmpuri = NULL;
 
@@ -1967,6 +1929,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                        j-1, c->argv[0] );
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                ldap_charray_free( uris );
+                               asyncmeta_target_free( mt );
                                return 1;
                        }
 
@@ -1983,6 +1946,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       asyncmeta_target_free( mt );
                                        return 1;
                                }
 
@@ -1999,6 +1963,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       asyncmeta_target_free( mt );
                                        return( 1 );
                                }
 
@@ -2021,6 +1986,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       asyncmeta_target_free( mt );
                                        return( 1 );
                                }
 
@@ -2032,6 +1998,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       asyncmeta_target_free( mt );
                                        return( 1 );
 
                                }
@@ -2043,6 +2010,7 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                                snprintf( c->cr_msg, sizeof( c->cr_msg ), "no memory?" );
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                ldap_charray_free( uris );
+                               asyncmeta_target_free( mt );
                                return( 1 );
                        }
                        ldap_memfree( uris[ j ] );
@@ -2054,7 +2022,10 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                if ( mt->mt_uri == NULL) {
                        snprintf( c->cr_msg, sizeof( c->cr_msg ), "no memory?" );
                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       asyncmeta_target_free( mt );
                        return( 1 );
+               } else {
+                       ldap_pvt_thread_mutex_init( &mt->mt_uri_mutex );
                }
 
                /*
@@ -2070,8 +2041,47 @@ asyncmeta_back_cf_gen( ConfigArgs *c )
                        snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "<naming context> of URI must be within the naming context of this database." );
                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       asyncmeta_target_free( mt );
+                       return 1;
+               }
+
+               i = mi->mi_ntargets++;
+
+               mi->mi_targets = ( a_metatarget_t ** )ch_realloc( mi->mi_targets,
+                       sizeof( a_metatarget_t * ) * mi->mi_ntargets );
+               if ( mi->mi_targets == NULL ) {
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
+                               "out of memory while storing server name"
+                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
+                               c->argv[0] );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       asyncmeta_target_free( mt );
+                       return 1;
+               }
+
+               mi->mi_targets[ i ] = mt;
+               if ( asyncmeta_back_new_target( mt, mi, c->be ) != 0 ) {
+                       /* does not currently happen, asyncmeta back_new_target always returns 0 */
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
+                               "unable to init server"
+                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
+                               c->argv[0] );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       asyncmeta_target_free( mt );
+                       mi->mi_ntargets--;
                        return 1;
                }
+
+
+               mt->mt_rebind_f = mi->mi_rebind_f;
+               mt->mt_urllist_f = mi->mi_urllist_f;
+               mt->mt_urllist_p = mt;
+
+               if ( META_BACK_QUARANTINE( mi ) ) {
+                       ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
+               }
+               mt->mt_mc = mi->mi_mc;
+
                c->ca_private = mt;
                config_push_cleanup( c, asyncmeta_cf_cleanup );
        } break;
index 45fccf03eca3958f0479dad27745ad3f42849af9..def44947450e3788c612ac700bcc8e8790032e09 100644 (file)
@@ -325,7 +325,7 @@ asyncmeta_back_clear_miconns( a_metainfo_t *mi )
        free(mi->mi_conns);
 }
 
-static void
+void
 asyncmeta_target_free(
        a_metatarget_t  *mt )
 {
index 941a743644b64d34a814f4b1eb83f4f15f900fa3..c767fa2639fbe10920a50bc265e45c40cbfd0d37 100644 (file)
@@ -685,6 +685,9 @@ meta_target_finish( metainfo_t *mi, metatarget_t *mt,
        const char *log, char *msg, size_t msize
 );
 
+extern void
+meta_back_target_free( metatarget_t    *mt );
+
 extern LDAP_REBIND_PROC                meta_back_default_rebind;
 extern LDAP_URLLIST_PROC       meta_back_default_urllist;
 
index 5c3dcfb62f8d9f0be31ed4c1cb831e156565cdbb..8b2cdbe81bbb31177bb446db105ef8466f895ea4 100644 (file)
@@ -565,16 +565,10 @@ meta_rwi_init( struct rewrite_info **rwm_rw )
 
 static int
 meta_back_new_target(
-       metatarget_t    **mtp )
+       metatarget_t    *mt )
 {
-       metatarget_t            *mt;
-
-       *mtp = NULL;
-
-       mt = ch_calloc( sizeof( metatarget_t ), 1 );
 
        if ( meta_rwi_init( &mt->mt_rwmap.rwm_rw )) {
-               ch_free( mt );
                return -1;
        }
 
@@ -587,8 +581,6 @@ meta_back_new_target(
        /* by default, use proxyAuthz control on each operation */
        mt->mt_idassert_flags = LDAP_BACK_AUTH_PRESCRIPTIVE;
 
-       *mtp = mt;
-
        return 0;
 }
 
@@ -1960,7 +1952,6 @@ meta_back_cf_gen( ConfigArgs *c )
                LDAPURLDesc     *ludp;
                struct berval   dn;
                int             j;
-
                char            **uris = NULL;
 
                if ( c->be->be_nsuffix == NULL ) {
@@ -1970,39 +1961,17 @@ meta_back_cf_gen( ConfigArgs *c )
                        return 1;
                }
 
-               i = mi->mi_ntargets++;
-
-               mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets,
-                       sizeof( metatarget_t * ) * mi->mi_ntargets );
-               if ( mi->mi_targets == NULL ) {
-                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
-                               "out of memory while storing server name"
-                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
-                               c->argv[0] );
-                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
-                       return 1;
-               }
-
-               if ( meta_back_new_target( &mi->mi_targets[ i ] ) != 0 ) {
+               mt = ch_calloc( sizeof( metatarget_t ), 1 );
+               if ( meta_back_new_target( mt ) != 0 ) {
                        snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "unable to init server"
                                " in \"%s <protocol>://<server>[:port]/<naming context>\"",
                                c->argv[0] );
                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       meta_back_target_free( mt );
                        return 1;
                }
 
-               mt = mi->mi_targets[ i ];
-
-               mt->mt_rebind_f = mi->mi_rebind_f;
-               mt->mt_urllist_f = mi->mi_urllist_f;
-               mt->mt_urllist_p = mt;
-
-               if ( META_BACK_QUARANTINE( mi ) ) {
-                       ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
-               }
-               mt->mt_mc = mi->mi_mc;
-
                for ( j = 1; j < c->argc; j++ ) {
                        char    **tmpuris = ldap_str2charray( c->argv[ j ], "\t" );
 
@@ -2012,6 +1981,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        " in \"%s <protocol>://<server>[:port]/<naming context>\"",
                                        j-1, c->argv[0] );
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                               meta_back_target_free( mt );
                                return 1;
                        }
 
@@ -2040,6 +2010,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        j-1, c->argv[0] );
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                ldap_charray_free( uris );
+                               meta_back_target_free( mt );
                                return 1;
                        }
 
@@ -2056,6 +2027,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       meta_back_target_free( mt );
                                        return 1;
                                }
 
@@ -2072,6 +2044,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       meta_back_target_free( mt );
                                        return( 1 );
                                }
 
@@ -2094,6 +2067,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       meta_back_target_free( mt );
                                        return( 1 );
                                }
 
@@ -2105,6 +2079,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                        ldap_free_urllist( ludp );
                                        ldap_charray_free( uris );
+                                       meta_back_target_free( mt );
                                        return( 1 );
 
                                }
@@ -2116,6 +2091,7 @@ meta_back_cf_gen( ConfigArgs *c )
                                snprintf( c->cr_msg, sizeof( c->cr_msg ), "no memory?" );
                                Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
                                ldap_charray_free( uris );
+                               meta_back_target_free( mt );
                                return( 1 );
                        }
                        ldap_memfree( uris[ j ] );
@@ -2127,6 +2103,7 @@ meta_back_cf_gen( ConfigArgs *c )
                if ( mt->mt_uri == NULL) {
                        snprintf( c->cr_msg, sizeof( c->cr_msg ), "no memory?" );
                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       meta_back_target_free( mt );
                        return( 1 );
                }
 
@@ -2143,8 +2120,34 @@ meta_back_cf_gen( ConfigArgs *c )
                        snprintf( c->cr_msg, sizeof( c->cr_msg ),
                                "<naming context> of URI must be within the naming context of this database." );
                        Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       meta_back_target_free( mt );
                        return 1;
                }
+
+               i = mi->mi_ntargets++;
+
+               mi->mi_targets = ( metatarget_t ** )ch_realloc( mi->mi_targets,
+                       sizeof( metatarget_t * ) * mi->mi_ntargets );
+               if ( mi->mi_targets == NULL ) {
+                       snprintf( c->cr_msg, sizeof( c->cr_msg ),
+                               "out of memory while storing server name"
+                               " in \"%s <protocol>://<server>[:port]/<naming context>\"",
+                               c->argv[0] );
+                       Debug( LDAP_DEBUG_ANY, "%s: %s.\n", c->log, c->cr_msg );
+                       meta_back_target_free( mt );
+                       return 1;
+               }
+
+               mi->mi_targets[i] = mt;
+               mt->mt_rebind_f = mi->mi_rebind_f;
+               mt->mt_urllist_f = mi->mi_urllist_f;
+               mt->mt_urllist_p = mt;
+
+               if ( META_BACK_QUARANTINE( mi ) ) {
+                       ldap_pvt_thread_mutex_init( &mt->mt_quarantine_mutex );
+               }
+
+               mt->mt_mc = mi->mi_mc;
                c->ca_private = mt;
                config_push_cleanup( c, meta_cf_cleanup );
        } break;
index 7e4b4c6d9b2dd7300630912af16022b6786d39ca..08890a74f18823a1118d0b96ca7afc2f0981f76e 100644 (file)
@@ -326,8 +326,8 @@ meta_back_map_free( struct ldapmap *lm )
        lm->map = NULL;
 }
 
-static void
-target_free(
+void
+meta_back_target_free(
        metatarget_t    *mt )
 {
        if ( mt->mt_uri ) {
@@ -433,7 +433,7 @@ meta_back_db_destroy(
                                        ldap_pvt_thread_mutex_destroy( &mt->mt_quarantine_mutex );
                                }
 
-                               target_free( mt );
+                               meta_back_target_free( mt );
                        }
 
                        free( mi->mi_targets );