Commit 757c8bed authored by Ondřej Kuzník's avatar Ondřej Kuzník
Browse files

Switch to ldap_parse_url_ext

This simplifies port parsing in the end. Also pass the url to
ldap_open_listener in anticipation of incremental listener config.
parent 93d20459
......@@ -966,17 +966,16 @@ backend_config_url( LloadBackend *b, struct berval *uri )
{
LDAPURLDesc *lud = NULL;
char *host = NULL;
int rc, port, proto, tls;
int rc, proto, tls;
/* Effect no changes until we've checked everything */
rc = ldap_url_parse( uri->bv_val, &lud );
rc = ldap_url_parse_ext( uri->bv_val, &lud, LDAP_PVT_URL_PARSE_DEF_PORT );
if ( rc != LDAP_URL_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "backend_config_url: "
"listen URL \"%s\" parse error=%d\n",
uri->bv_val, rc );
rc = -1;
goto done;
return -1;
}
tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
......@@ -994,12 +993,6 @@ backend_config_url( LloadBackend *b, struct berval *uri )
#endif /* ! HAVE_TLS */
}
if ( !lud->lud_port ) {
port = tls ? LDAPS_PORT : LDAP_PORT;
} else {
port = lud->lud_port;
}
proto = ldap_pvt_url_scheme2proto( lud->lud_scheme );
if ( proto == LDAP_PROTO_IPC ) {
#ifdef LDAP_PF_LOCAL
......@@ -1033,7 +1026,7 @@ backend_config_url( LloadBackend *b, struct berval *uri )
b->b_proto = proto;
b->b_tls = tls;
b->b_port = port;
b->b_port = lud->lud_port;
b->b_host = ch_strdup( host );
done:
......@@ -1217,7 +1210,7 @@ tcp_buffer_parse(
if ( strncasecmp( argv[i], "listener=", STRLENOF("listener=") ) == 0 ) {
char *url = argv[i] + STRLENOF("listener=");
if ( ldap_url_parse( url, &lud ) ) {
if ( ldap_url_parse_ext( url, &lud, LDAP_PVT_URL_PARSE_DEF_PORT ) ) {
rc = LDAP_INVALID_SYNTAX;
goto done;
}
......@@ -3406,7 +3399,8 @@ lload_config_check_my_url( const char *url, LDAPURLDesc *lud )
!strcasecmp( global_host, lud->lud_host ) ) {
for ( i = 0; l && l[i]; i++ ) {
LDAPURLDesc *lu2;
ldap_url_parse( l[i]->sl_url.bv_val, &lu2 );
ldap_url_parse_ext(
l[i]->sl_url.bv_val, &lu2, LDAP_PVT_URL_PARSE_DEF_PORT );
do {
if ( strcasecmp( lud->lud_scheme, lu2->lud_scheme ) ) break;
if ( lud->lud_port != lu2->lud_port ) break;
......
......@@ -396,12 +396,15 @@ errexit:
}
static int
lload_open_listener( const char *url, int *listeners, int *cur )
lload_open_listener(
const char *url,
LDAPURLDesc *lud,
int *listeners,
int *cur )
{
int num, tmp, rc;
LloadListener l;
LloadListener *li;
LDAPURLDesc *lud;
unsigned short port;
int err, addrlen = 0;
struct sockaddr **sal = NULL, **psal;
......@@ -416,14 +419,8 @@ lload_open_listener( const char *url, int *listeners, int *cur )
int crit = 1;
#endif /* LDAP_PF_LOCAL || SLAP_X_LISTENER_MOD */
rc = ldap_url_parse( url, &lud );
if ( rc != LDAP_URL_SUCCESS ) {
Debug( LDAP_DEBUG_ANY, "lload_open_listener: "
"listen URL \"%s\" parse error=%d\n",
url, rc );
return rc;
}
assert( url );
assert( lud );
l.sl_url.bv_val = NULL;
l.sl_mute = 0;
......@@ -442,10 +439,6 @@ lload_open_listener( const char *url, int *listeners, int *cur )
#else /* HAVE_TLS */
l.sl_is_tls = ldap_pvt_url_scheme2tls( lud->lud_scheme );
if ( !lud->lud_port ) {
lud->lud_port = l.sl_is_tls ? LDAPS_PORT : LDAP_PORT;
}
#endif /* HAVE_TLS */
#ifdef LDAP_TCP_BUFFER
......@@ -712,12 +705,13 @@ lload_open_listener( const char *url, int *listeners, int *cur )
int lloadd_inited = 0;
int
lloadd_daemon_init( const char *urls )
lloadd_listeners_init( const char *urls )
{
int i, j, n;
char **u;
LDAPURLDesc *lud;
Debug( LDAP_DEBUG_ARGS, "lloadd_daemon_init: %s\n",
Debug( LDAP_DEBUG_ARGS, "lloadd_listeners_init: %s\n",
urls ? urls : "<null>" );
#ifdef HAVE_TCPD
......@@ -729,7 +723,7 @@ lloadd_daemon_init( const char *urls )
u = ldap_str2charray( urls, " " );
if ( u == NULL || u[0] == NULL ) {
Debug( LDAP_DEBUG_ANY, "lloadd_daemon_init: "
Debug( LDAP_DEBUG_ANY, "lloadd_listeners_init: "
"no urls (%s) provided\n",
urls );
if ( u ) ldap_charray_free( u );
......@@ -737,33 +731,41 @@ lloadd_daemon_init( const char *urls )
}
for ( i = 0; u[i] != NULL; i++ ) {
Debug( LDAP_DEBUG_TRACE, "lloadd_daemon_init: "
Debug( LDAP_DEBUG_TRACE, "lloadd_listeners_init: "
"listen on %s\n",
u[i] );
}
if ( i == 0 ) {
Debug( LDAP_DEBUG_ANY, "lloadd_daemon_init: "
Debug( LDAP_DEBUG_ANY, "lloadd_listeners_init: "
"no listeners to open (%s)\n",
urls );
ldap_charray_free( u );
return -1;
}
Debug( LDAP_DEBUG_TRACE, "lloadd_daemon_init: "
Debug( LDAP_DEBUG_TRACE, "lloadd_listeners_init: "
"%d listeners to open...\n",
i );
lload_listeners = ch_malloc( ( i + 1 ) * sizeof(LloadListener *) );
for ( n = 0, j = 0; u[n]; n++ ) {
if ( lload_open_listener( u[n], &i, &j ) ) {
if ( ldap_url_parse_ext( u[n], &lud, LDAP_PVT_URL_PARSE_DEF_PORT ) ) {
Debug( LDAP_DEBUG_ANY, "lloadd_listeners_init: "
"could not parse url %s\n",
u[n] );
ldap_charray_free( u );
return -1;
}
if ( lload_open_listener( u[n], lud, &i, &j ) ) {
ldap_charray_free( u );
return -1;
}
}
lload_listeners[j] = NULL;
Debug( LDAP_DEBUG_TRACE, "lloadd_daemon_init: "
Debug( LDAP_DEBUG_TRACE, "lloadd_listeners_init: "
"%d listeners opened\n",
i );
......
......@@ -627,7 +627,7 @@ unhandled_option:;
global_host = ldap_pvt_get_fqdn( NULL );
if ( check == CHECK_NONE && lloadd_daemon_init( urls ) != 0 ) {
if ( check == CHECK_NONE && lloadd_listeners_init( urls ) != 0 ) {
rc = 1;
SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 );
goto stop;
......
......@@ -89,7 +89,7 @@ lload_back_open( BackendInfo *bi )
return -1;
}
if ( lloadd_daemon_init( listeners_list ) != 0 ) {
if ( lloadd_listeners_init( listeners_list ) != 0 ) {
return -1;
}
......
......@@ -97,7 +97,7 @@ LDAP_SLAPD_F (void) connection_destroy( LloadConnection *c );
/*
* daemon.c
*/
LDAP_SLAPD_F (int) lloadd_daemon_init( const char *urls );
LDAP_SLAPD_F (int) lloadd_listeners_init( const char *urls );
LDAP_SLAPD_F (int) lloadd_daemon_destroy( void );
LDAP_SLAPD_F (int) lloadd_daemon( struct event_base *daemon_base );
LDAP_SLAPD_F (LloadListener **) lloadd_get_listeners( void );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment