From: Howard Chu Date: Thu, 8 Jun 2006 11:37:14 +0000 (+0000) Subject: ITS#4580 make sure port number is preserved in replica info X-Git-Tag: OPENLDAP_REL_ENG_2_4_3ALPHA~9^2~173 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=f15e31b9a9baf0d903cb4abffe58b56680003790;p=openldap ITS#4580 make sure port number is preserved in replica info --- diff --git a/servers/slapd/bconfig.c b/servers/slapd/bconfig.c index 003b4d61a0..ec21bdc210 100644 --- a/servers/slapd/bconfig.c +++ b/servers/slapd/bconfig.c @@ -2616,6 +2616,8 @@ config_replica(ConfigArgs *c) { nr = add_replica_info(c->be, replicauri, replicahost); break; } else if(!strncasecmp(c->argv[i], "uri=", STRLENOF("uri="))) { + ber_len_t len; + if ( replicauri ) { snprintf( c->msg, sizeof( c->msg ), "<%s> replica host/URI already specified", c->argv[0] ); Debug(LDAP_DEBUG_ANY, "%s: %s \"%s\"\n", c->log, c->msg, replicauri ); @@ -2634,11 +2636,27 @@ config_replica(ConfigArgs *c) { Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); return(1); } + + len = strlen(ludp->lud_scheme) + strlen(ludp->lud_host) + + STRLENOF("://") + 1; + if (ludp->lud_port != LDAP_PORT) { + if (ludp->lud_port < 1 || ludp->lud_port > 65535) { + snprintf( c->msg, sizeof( c->msg ), "<%s> invalid port", + c->argv[0] ); + Debug(LDAP_DEBUG_ANY, "%s: %s\n", c->log, c->msg, 0 ); + return(1); + } + len += STRLENOF(":65535"); + } + replicauri = ch_malloc( len ); + replicahost = lutil_strcopy( replicauri, ludp->lud_scheme ); + replicahost = lutil_strcopy( replicauri, "://" ); + if (ludp->lud_port == LDAP_PORT) { + strcpy( replicahost, ludp->lud_host ); + } else { + sprintf( replicahost, "%s:%d",ludp->lud_host,ludp->lud_port ); + } ldap_free_urldesc(ludp); - replicauri = c->argv[i] + STRLENOF("uri="); - replicauri = ch_strdup( replicauri ); - replicahost = strchr( replicauri, '/' ); - replicahost += 2; nr = add_replica_info(c->be, replicauri, replicahost); break; }