From 28aca605c7b475a4fc09854ba6a596bcd731d60f Mon Sep 17 00:00:00 2001 From: Pierangelo Masarati Date: Wed, 16 Nov 2005 21:52:14 +0000 Subject: [PATCH] more URI into bindconf --- servers/slapd/bconfig.c | 39 ++++++++++++++++++++++++++++----------- servers/slapd/config.c | 5 +++++ servers/slapd/repl.c | 5 +---- servers/slapd/slap.h | 2 +- servers/slapd/syncrepl.c | 27 ++++++++++++++------------- 5 files changed, 49 insertions(+), 29 deletions(-) diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index a1545a1cb6..ca571b70e0 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2337,6 +2337,8 @@ replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv ) struct berval bc = BER_BVNULL; char numbuf[32]; + assert( !BER_BVISNULL( &ri->ri_bindconf.sb_uri ) ); + BER_BVZERO( bv ); len = snprintf(numbuf, sizeof( numbuf ), SLAP_X_ORDERED_FMT, i ); @@ -2345,14 +2347,13 @@ replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv ) return; } - len += strlen( ri->ri_uri ) + STRLENOF("uri="); if ( ri->ri_nsuffix ) { for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) { len += ri->ri_nsuffix[i].bv_len + STRLENOF(" suffix=\"\""); } } if ( ri->ri_attrs ) { - len += STRLENOF("attr"); + len += STRLENOF(" attrs"); if ( ri->ri_exclude ) len++; for (i=0; !BER_BVISNULL( &ri->ri_attrs[i].an_name ); i++) { len += 1 + ri->ri_attrs[i].an_name.bv_len; @@ -2365,8 +2366,13 @@ replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv ) bv->bv_len = len; ptr = lutil_strcopy( bv->bv_val, numbuf ); - ptr = lutil_strcopy( ptr, "uri=" ); - ptr = lutil_strcopy( ptr, ri->ri_uri ); + + /* start with URI from bindconf */ + assert( !BER_BVISNULL( &bc ) ); + if ( bc.bv_val ) { + strcpy( ptr, bc.bv_val ); + ch_free( bc.bv_val ); + } if ( ri->ri_nsuffix ) { for (i=0; !BER_BVISNULL( &ri->ri_nsuffix[i] ); i++) { @@ -2376,15 +2382,11 @@ replica_unparse( struct slap_replica_info *ri, int i, struct berval *bv ) } } if ( ri->ri_attrs ) { - ptr = lutil_strcopy( ptr, "attr" ); + ptr = lutil_strcopy( ptr, " attrs" ); if ( ri->ri_exclude ) *ptr++ = '!'; *ptr++ = '='; ptr = anlist_unparse( ri->ri_attrs, ptr ); } - if ( bc.bv_val ) { - strcpy( ptr, bc.bv_val ); - ch_free( bc.bv_val ); - } } static int @@ -2472,7 +2474,11 @@ config_replica(ConfigArgs *c) { return(1); } else { for(i = 1; i < c->argc; i++) { - if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) { + if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) { + /* dealt with separately; don't let it get to bindconf */ + ; + + } else if(!strncasecmp(c->argv[i], "suffix=", STRLENOF( "suffix="))) { switch(add_replica_suffix(c->be, nr, c->argv[i] + STRLENOF("suffix="))) { case 1: Debug( SLAPD_DEBUG_CONFIG_ERROR, "%s: " @@ -2494,9 +2500,20 @@ config_replica(ConfigArgs *c) { break; } - } else if(!strncasecmp(c->argv[i], "attr", STRLENOF("attr"))) { + } else if (!strncasecmp(c->argv[i], "attr", STRLENOF("attr")) + || !strncasecmp(c->argv[i], "attrs", STRLENOF("attrs"))) + { int exclude = 0; char *arg = c->argv[i] + STRLENOF("attr"); + if (arg[0] == 's') { + arg++; + } else { + Debug( LDAP_DEBUG_ANY, + "%s: \"attr\" " + "is deprecated (and undocumented); " + "use \"attrs\" instead.\n", + c->log, 0, 0 ); + } if(arg[0] == '!') { arg++; exclude = 1; diff --git a/servers/slapd/config.c b/servers/slapd/config.c index da85ee01ab..cbc9f21ec6 100644 --- a/servers/slapd/config.c +++ b/servers/slapd/config.c @@ -992,6 +992,7 @@ static slap_verbmasks methkey[] = { }; static slap_cf_aux_table bindkey[] = { + { BER_BVC("uri="), offsetof(slap_bindconf, sb_uri), 'b', 1, NULL }, { BER_BVC("starttls="), offsetof(slap_bindconf, sb_tls), 'd', 0, tlskey }, { BER_BVC("bindmethod="), offsetof(slap_bindconf, sb_method), 'd', 0, methkey }, { BER_BVC("binddn="), offsetof(slap_bindconf, sb_binddn), 'b', 1, NULL }, @@ -1151,6 +1152,10 @@ bindconf_unparse( slap_bindconf *bc, struct berval *bv ) } void bindconf_free( slap_bindconf *bc ) { + if ( !BER_BVISNULL( &bc->sb_uri ) ) { + ch_free( bc->sb_uri.bv_val ); + BER_BVZERO( &bc->sb_uri ); + } if ( !BER_BVISNULL( &bc->sb_binddn ) ) { ch_free( bc->sb_binddn.bv_val ); BER_BVZERO( &bc->sb_binddn ); diff --git a/servers/slapd/repl.c b/servers/slapd/repl.c index 8931915219..73b3c8ca96 100644 --- a/servers/slapd/repl.c +++ b/servers/slapd/repl.c @@ -59,7 +59,7 @@ add_replica_info( be->be_replica[ i ] = ch_calloc( sizeof( struct slap_replica_info ), 1 ); - be->be_replica[ i ]->ri_uri = uri; + ber_str2bv( uri, 0, 0, &be->be_replica[ i ]->ri_bindconf.sb_uri ); be->be_replica[ i ]->ri_host = host; be->be_replica[ i ]->ri_nsuffix = NULL; be->be_replica[ i ]->ri_attrs = NULL; @@ -81,9 +81,6 @@ destroy_replica_info( } for ( ; be->be_replica[ i ] != NULL; i++ ) { - - ch_free( (char *)be->be_replica[ i ]->ri_uri ); - ber_bvarray_free( be->be_replica[ i ]->ri_nsuffix ); if ( be->be_replica[ i ]->ri_attrs ) { diff --git a/servers/slapd/slap.h b/servers/slapd/slap.h index 1d81e8abaa..5f280d3663 100644 --- a/servers/slapd/slap.h +++ b/servers/slapd/slap.h @@ -1543,6 +1543,7 @@ LDAP_SLAPD_V (int) slapMode; #define SB_TLS_CRITICAL 2 typedef struct slap_bindconf { + struct berval sb_uri; int sb_tls; int sb_method; struct berval sb_binddn; @@ -1555,7 +1556,6 @@ typedef struct slap_bindconf { } slap_bindconf; struct slap_replica_info { - const char *ri_uri; /* supersedes be_replica */ const char *ri_host; /* points to host part of uri */ BerVarray ri_nsuffix; /* array of suffixes this replica accepts */ AttributeName *ri_attrs; /* attrs to replicate, NULL=all */ diff --git a/servers/slapd/syncrepl.c b/servers/slapd/syncrepl.c index b694ee2091..a801e54a7c 100644 --- a/servers/slapd/syncrepl.c +++ b/servers/slapd/syncrepl.c @@ -48,7 +48,6 @@ typedef struct syncinfo_s { struct slap_backend_db *si_be; struct re_s *si_re; long si_rid; - struct berval si_provideruri; slap_bindconf si_bindconf; struct berval si_base; struct berval si_logbase; @@ -420,11 +419,11 @@ do_syncrep1( psub = &si->si_be->be_nsuffix[0]; /* Init connection to master */ - rc = ldap_initialize( &si->si_ld, si->si_provideruri.bv_val ); + rc = ldap_initialize( &si->si_ld, si->si_bindconf.sb_uri.bv_val ); if ( rc != LDAP_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "do_syncrep1: ldap_initialize failed (%s)\n", - si->si_provideruri.bv_val, 0, 0 ); + si->si_bindconf.sb_uri.bv_val, 0, 0 ); return rc; } @@ -455,7 +454,7 @@ do_syncrep1( if( rc != LDAP_OPT_SUCCESS ) { Debug( LDAP_DEBUG_ANY, "Error: ldap_set_option " "(%s,SECPROPS,\"%s\") failed!\n", - si->si_provideruri.bv_val, si->si_bindconf.sb_secprops, 0 ); + si->si_bindconf.sb_uri.bv_val, si->si_bindconf.sb_secprops, 0 ); goto done; } } @@ -2559,9 +2558,6 @@ void syncinfo_free( syncinfo_t *sie ) { ldap_pvt_thread_mutex_destroy( &sie->si_mutex ); - if ( !BER_BVISNULL( &sie->si_provideruri ) ) { - ch_free( sie->si_provideruri.bv_val ); - } bindconf_free( &sie->si_bindconf ); @@ -2733,7 +2729,7 @@ parse_syncrepl_line( STRLENOF( PROVIDERSTR "=" ) ) ) { val = cargv[ i ] + STRLENOF( PROVIDERSTR "=" ); - ber_str2bv( val, 0, 1, &si->si_provideruri ); + ber_str2bv( val, 0, 1, &si->si_bindconf.sb_uri ); gots |= GOT_PROVIDER; } else if ( !strncasecmp( cargv[ i ], SCHEMASTR "=", STRLENOF( SCHEMASTR "=" ) ) ) @@ -3091,8 +3087,8 @@ add_syncrepl( } else { Debug( LDAP_DEBUG_CONFIG, "Config: ** successfully added syncrepl \"%s\"\n", - BER_BVISNULL( &si->si_provideruri ) ? - "(null)" : si->si_provideruri.bv_val, 0, 0 ); + BER_BVISNULL( &si->si_bindconf.sb_uri ) ? + "(null)" : si->si_bindconf.sb_uri.bv_val, 0, 0 ); if ( !si->si_schemachecking ) { SLAP_DBFLAGS(be) |= SLAP_DBFLAG_NO_SCHEMA_CHECK; } @@ -3104,14 +3100,19 @@ add_syncrepl( static void syncrepl_unparse( syncinfo_t *si, struct berval *bv ) { - struct berval bc; + struct berval bc, uri; char buf[BUFSIZ*2], *ptr; int i; + /* temporarily inhibit bindconf from printing URI */ + uri = si->si_bindconf.sb_uri; + BER_BVZERO( &si->si_bindconf.sb_uri ); bindconf_unparse( &si->si_bindconf, &bc ); + si->si_bindconf.sb_uri = uri; + ptr = buf; - ptr += sprintf( ptr, IDSTR "=%03ld " PROVIDERSTR "=%s", - si->si_rid, si->si_provideruri.bv_val ); + ptr += snprintf( ptr, sizeof( buf ), IDSTR "=%03ld " PROVIDERSTR "=%s", + si->si_rid, si->si_bindconf.sb_uri.bv_val ); if ( !BER_BVISNULL( &bc )) { ptr = lutil_strcopy( ptr, bc.bv_val ); free( bc.bv_val ); -- 2.39.5