diff --git a/servers/lloadd/backend.c b/servers/lloadd/backend.c index f9fed313a5..d180d246b9 100644 --- a/servers/lloadd/backend.c +++ b/servers/lloadd/backend.c @@ -510,6 +510,7 @@ lload_backend_destroy( LloadBackend *b ) ch_free( b->b_host ); ch_free( b->b_uri.bv_val ); + ch_free( b->b_name.bv_val ); ch_free( b ); } diff --git a/servers/lloadd/config.c b/servers/lloadd/config.c index 238f95aff3..25a3ef12f0 100644 --- a/servers/lloadd/config.c +++ b/servers/lloadd/config.c @@ -1085,7 +1085,7 @@ config_bindconf( ConfigArgs *c ) lload_bindconf_unparse( &bindconf, &bv ); - for ( i = 0; isspace((unsigned char)bv.bv_val[i]); i++ ) + for ( i = 0; isspace( (unsigned char)bv.bv_val[i] ); i++ ) /* count spaces */; if ( i ) { @@ -3563,6 +3563,11 @@ static int lload_backend_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca ) { LloadBackend *b; + Attribute *a; + AttributeDescription *ad = NULL; + struct berval bv, type, rdn; + const char *text; + char *name; Debug( LDAP_DEBUG_TRACE, "lload_backend_ldadd: " "a new backend-server is being added\n" ); @@ -3571,7 +3576,26 @@ lload_backend_ldadd( CfEntryInfo *p, Entry *e, ConfigArgs *ca ) p->ce_bi->bi_cf_ocs != lloadocs ) return LDAP_CONSTRAINT_VIOLATION; + dnRdn( &e->e_name, &rdn ); + type.bv_len = strchr( rdn.bv_val, '=' ) - rdn.bv_val; + type.bv_val = rdn.bv_val; + + /* Find attr */ + slap_bv2ad( &type, &ad, &text ); + if ( ad != slap_schema.si_ad_cn ) return LDAP_NAMING_VIOLATION; + + a = attr_find( e->e_attrs, ad ); + if ( !a || a->a_numvals != 1 ) return LDAP_NAMING_VIOLATION; + bv = a->a_vals[0]; + + if ( bv.bv_val[0] == '{' && ( name = strchr( bv.bv_val, '}' ) ) ) { + name++; + bv.bv_len -= name - bv.bv_val; + bv.bv_val = name; + } + b = backend_alloc(); + ber_dupbv( &b->b_name, &bv ); ca->bi = p->ce_bi; ca->ca_private = b; @@ -3611,9 +3635,14 @@ lload_cfadd( Operation *op, SlapReply *rs, Entry *p, ConfigArgs *c ) bv.bv_val = c->cr_msg; LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) { + char buf[STRLENOF( "server 4294967295" ) + 1] = { 0 }; + bv.bv_len = snprintf( c->cr_msg, sizeof(c->cr_msg), "cn=" SLAP_X_ORDERED_FMT "server %d", i, i + 1 ); + snprintf( buf, sizeof(buf), "server %d", i + 1 ); + ber_str2bv( buf, 0, 1, &b->b_name ); + c->ca_private = b; c->valx = i; diff --git a/servers/lloadd/lload.h b/servers/lloadd/lload.h index 85f2acbc9d..80156ccef4 100644 --- a/servers/lloadd/lload.h +++ b/servers/lloadd/lload.h @@ -188,7 +188,7 @@ typedef struct lload_global_stats_t { struct LloadBackend { ldap_pvt_thread_mutex_t b_mutex; - struct berval b_uri; + struct berval b_name, b_uri; int b_proto, b_port; enum lload_tls_type b_tls; char *b_host; diff --git a/servers/lloadd/monitor.c b/servers/lloadd/monitor.c index 55bc207915..8efe3d7b48 100644 --- a/servers/lloadd/monitor.c +++ b/servers/lloadd/monitor.c @@ -687,9 +687,6 @@ done: return rc; } -static struct monitor_subsys_t *servers_subsys; -/* Not sure if this has to be a subsystem at all, perhaps just entries? */ - static int lload_monitor_server_update( Operation *op, @@ -816,7 +813,6 @@ lload_monitor_backends_init( BackendDB *be, monitor_subsys_t *ms ) { monitor_extra_t *mbe; Entry *e; - unsigned int i = 1, j = 0; int rc; LloadBackend *b; @@ -847,22 +843,15 @@ lload_monitor_backends_init( BackendDB *be, monitor_subsys_t *ms ) } LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) { - j++; - } + monitor_subsys_t *bk_mss = ch_calloc( 1, sizeof(monitor_subsys_t) ); - servers_subsys = ch_calloc( j, sizeof(monitor_subsys_t) ); - LDAP_CIRCLEQ_FOREACH ( b, &backend, b_next ) { - monitor_subsys_t *bk_mss; - struct berval bv; + bk_mss->mss_rdn.bv_len = sizeof("cn=") + b->b_name.bv_len; + bk_mss->mss_rdn.bv_val = ch_malloc( bk_mss->mss_rdn.bv_len ); + bk_mss->mss_rdn.bv_len = snprintf( bk_mss->mss_rdn.bv_val, + bk_mss->mss_rdn.bv_len, "cn=%s", b->b_name.bv_val ); - bv.bv_len = sizeof( "cn=Server 4294967295" ); - bv.bv_val = ch_malloc( bv.bv_len ); - bv.bv_len = snprintf( bv.bv_val, bv.bv_len, "cn=Server %u", i ); - - bk_mss = &servers_subsys[i - 1]; - bk_mss->mss_name = bv.bv_val; ber_str2bv( LLOAD_MONITOR_BACKENDS_DN, 0, 0, &bk_mss->mss_dn ); - ber_dupbv( &bk_mss->mss_rdn, &bv ); + bk_mss->mss_name = b->b_name.bv_val; bk_mss->mss_flags = MONITOR_F_VOLATILE_CH; bk_mss->mss_open = lload_monitor_backend_open; bk_mss->mss_create = lload_monitor_up_conn_create; @@ -876,7 +865,6 @@ lload_monitor_backends_init( BackendDB *be, monitor_subsys_t *ms ) bk_mss->mss_name ); return -1; } - i++; } done: entry_free( e );