From: Pierangelo Masarati Date: Tue, 4 Feb 2003 18:49:58 +0000 (+0000) Subject: allow multiple URIs (need to backport to back-ldap) X-Git-Tag: NO_SLAP_OP_BLOCKS~445 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=c432154ad18b6217e3e55f6a005afd16ffb20bfd;p=openldap allow multiple URIs (need to backport to back-ldap) --- diff --git a/libraries/libldap/url.c b/libraries/libldap/url.c index 85480bd9bf..788a601f72 100644 --- a/libraries/libldap/url.c +++ b/libraries/libldap/url.c @@ -1042,9 +1042,13 @@ ldap_url_list2urls( /* figure out how big the string is */ size = 1; /* nul-term */ for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) { - size += strlen(ludp->lud_scheme) + strlen(ludp->lud_host); - if (strchr(ludp->lud_host, ':')) /* will add [ ] below */ - size += 2; + size += strlen(ludp->lud_scheme); + if ( ludp->lud_host ) { + size += strlen(ludp->lud_host); + /* will add [ ] below */ + if (strchr(ludp->lud_host, ':')) + size += 2; + } size += sizeof(":/// "); if (ludp->lud_port != 0) { @@ -1059,9 +1063,11 @@ ldap_url_list2urls( p = s; for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) { - p += sprintf(p, - strchr(ludp->lud_host, ':') ? "%s://[%s]" : "%s://%s", - ludp->lud_scheme, ludp->lud_host); + p += sprintf(p, "%s://", ludp->lud_scheme); + if ( ludp->lud_host ) { + p += sprintf(p, strchr(ludp->lud_host, ':') + ? "[%s]" : "%s", ludp->lud_host); + } if (ludp->lud_port != 0) p += sprintf(p, ":%d", ludp->lud_port); *p++ = '/'; diff --git a/servers/slapd/back-meta/config.c b/servers/slapd/back-meta/config.c index d8cd35a6b8..80305f4aba 100644 --- a/servers/slapd/back-meta/config.c +++ b/servers/slapd/back-meta/config.c @@ -73,6 +73,7 @@ #include "slap.h" #include "../back-ldap/back-ldap.h" +#include "../../../libraries/libldap/ldap-int.h" #include "back-meta.h" static struct metatarget * @@ -121,8 +122,7 @@ meta_back_db_config( #if 0 int j; #endif /* uncomment if uri MUST be a branch of suffix */ - LDAPURLDesc *ludp; - char *last; + LDAPURLDesc *ludp, *tmpludp; struct berval dn; int rc; @@ -157,7 +157,7 @@ meta_back_db_config( /* * uri MUST be legal! */ - if ( ldap_url_parse( argv[ 1 ], &ludp ) != LDAP_SUCCESS ) { + if ( ldap_url_parselist( &ludp, argv[ 1 ] ) != LDAP_SUCCESS ) { fprintf( stderr, "%s: line %d: unable to parse URI" " in \"uri ://[:port]/\" line\n", @@ -191,10 +191,25 @@ meta_back_db_config( return( 1 ); } - li->targets[ i ]->uri = ch_strdup( argv[ 1 ] ); - last = strstr( li->targets[ i ]->uri, ludp->lud_dn ); - assert( last != NULL ); - last[ 0 ] = '\0'; + ludp->lud_dn[ 0 ] = '\0'; + + for ( tmpludp = ludp->lud_next; tmpludp; tmpludp = tmpludp->lud_next ) { + if ( tmpludp->lud_dn != NULL && tmpludp->lud_dn[ 0 ] != '\0' ) { + fprintf( stderr, "%s: line %d: " + "multiple URIs must have no DN part\n", + fname, lineno, argv[ 1 ] ); + return( 1 ); + + } + } + + li->targets[ i ]->uri = ldap_url_list2urls( ludp ); + ldap_free_urllist( ludp ); + if ( li->targets[ i ]->uri == NULL) { + fprintf( stderr, "%s: line %d: no memory?\n", + fname, lineno ); + return( 1 ); + } /* * uri MUST be a branch of suffix! @@ -238,8 +253,6 @@ meta_back_db_config( } } #endif - - ldap_free_urldesc( ludp ); #if 0 fprintf(stderr, "%s: line %d: URI \"%s\", suffix \"%s\"\n",