allow multiple URIs (need to backport to back-ldap)

This commit is contained in:
Pierangelo Masarati 2003-02-04 18:49:58 +00:00
parent f894db3be2
commit c432154ad1
2 changed files with 34 additions and 15 deletions

View File

@ -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++ = '/';

View File

@ -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 <protocol>://<server>[:port]/<naming context>\" 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",