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 */ /* figure out how big the string is */
size = 1; /* nul-term */ size = 1; /* nul-term */
for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) { for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
size += strlen(ludp->lud_scheme) + strlen(ludp->lud_host); size += strlen(ludp->lud_scheme);
if (strchr(ludp->lud_host, ':')) /* will add [ ] below */ if ( ludp->lud_host ) {
size += strlen(ludp->lud_host);
/* will add [ ] below */
if (strchr(ludp->lud_host, ':'))
size += 2; size += 2;
}
size += sizeof(":/// "); size += sizeof(":/// ");
if (ludp->lud_port != 0) { if (ludp->lud_port != 0) {
@ -1059,9 +1063,11 @@ ldap_url_list2urls(
p = s; p = s;
for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) { for (ludp = ludlist; ludp != NULL; ludp = ludp->lud_next) {
p += sprintf(p, p += sprintf(p, "%s://", ludp->lud_scheme);
strchr(ludp->lud_host, ':') ? "%s://[%s]" : "%s://%s", if ( ludp->lud_host ) {
ludp->lud_scheme, ludp->lud_host); p += sprintf(p, strchr(ludp->lud_host, ':')
? "[%s]" : "%s", ludp->lud_host);
}
if (ludp->lud_port != 0) if (ludp->lud_port != 0)
p += sprintf(p, ":%d", ludp->lud_port); p += sprintf(p, ":%d", ludp->lud_port);
*p++ = '/'; *p++ = '/';

View File

@ -73,6 +73,7 @@
#include "slap.h" #include "slap.h"
#include "../back-ldap/back-ldap.h" #include "../back-ldap/back-ldap.h"
#include "../../../libraries/libldap/ldap-int.h"
#include "back-meta.h" #include "back-meta.h"
static struct metatarget * static struct metatarget *
@ -121,8 +122,7 @@ meta_back_db_config(
#if 0 #if 0
int j; int j;
#endif /* uncomment if uri MUST be a branch of suffix */ #endif /* uncomment if uri MUST be a branch of suffix */
LDAPURLDesc *ludp; LDAPURLDesc *ludp, *tmpludp;
char *last;
struct berval dn; struct berval dn;
int rc; int rc;
@ -157,7 +157,7 @@ meta_back_db_config(
/* /*
* uri MUST be legal! * uri MUST be legal!
*/ */
if ( ldap_url_parse( argv[ 1 ], &ludp ) != LDAP_SUCCESS ) { if ( ldap_url_parselist( &ludp, argv[ 1 ] ) != LDAP_SUCCESS ) {
fprintf( stderr, fprintf( stderr,
"%s: line %d: unable to parse URI" "%s: line %d: unable to parse URI"
" in \"uri <protocol>://<server>[:port]/<naming context>\" line\n", " in \"uri <protocol>://<server>[:port]/<naming context>\" line\n",
@ -191,10 +191,25 @@ meta_back_db_config(
return( 1 ); return( 1 );
} }
li->targets[ i ]->uri = ch_strdup( argv[ 1 ] ); ludp->lud_dn[ 0 ] = '\0';
last = strstr( li->targets[ i ]->uri, ludp->lud_dn );
assert( last != NULL ); for ( tmpludp = ludp->lud_next; tmpludp; tmpludp = tmpludp->lud_next ) {
last[ 0 ] = '\0'; 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! * uri MUST be a branch of suffix!
@ -239,8 +254,6 @@ meta_back_db_config(
} }
#endif #endif
ldap_free_urldesc( ludp );
#if 0 #if 0
fprintf(stderr, "%s: line %d: URI \"%s\", suffix \"%s\"\n", fprintf(stderr, "%s: line %d: URI \"%s\", suffix \"%s\"\n",
fname, lineno, li->targets[ i ]->uri, fname, lineno, li->targets[ i ]->uri,