From 6847e329bcc4d3293b92742213d8f04b57e0ad02 Mon Sep 17 00:00:00 2001 From: Kurt Zeilenga Date: Mon, 19 Jul 1999 20:48:19 +0000 Subject: [PATCH] Fix new URL startup code. --- servers/slapd/daemon.c | 49 ++++++++++++++++++++++++++++++------------ servers/slapd/main.c | 6 +++++- 2 files changed, 40 insertions(+), 15 deletions(-) diff --git a/servers/slapd/daemon.c b/servers/slapd/daemon.c index be475f30f1..596233e827 100644 --- a/servers/slapd/daemon.c +++ b/servers/slapd/daemon.c @@ -33,7 +33,7 @@ typedef struct slap_listener { struct sockaddr_in sl_addr; } Listener; -Listener **slap_listeners; +Listener **slap_listeners = NULL; #ifdef HAVE_WINSOCK2 /* in nt_main.c */ @@ -196,7 +196,7 @@ static void slapd_close(ber_socket_t s) { Listener * open_listener( - char* url, + const char* url, int port, int tls_port ) { @@ -228,6 +228,8 @@ open_listener( } #else + l.sl_is_tls = lud->lud_ldaps; + if(! lud->lud_port ) { lud->lud_port = lud->lud_ldaps ? tls_port : port; } @@ -298,7 +300,7 @@ open_listener( WSAGetLastError(), WSAGetLastErrorString(), 0 ); #endif - return( AC_SOCKET_INVALID ); + return NULL; } #ifndef HAVE_WINSOCK @@ -307,7 +309,7 @@ open_listener( "daemon: listener descriptor %ld is too great %ld\n", (long) l.sl_sd, (long) dtblsize, 0 ); tcp_close( l.sl_sd ); - return( AC_SOCKET_INVALID ); + return NULL; } #endif @@ -345,7 +347,7 @@ open_listener( err > -1 && err < sys_nerr ? sys_errlist[err] : "unknown" ); tcp_close( l.sl_sd ); - return AC_SOCKET_INVALID; + return NULL; } l.sl_url = ch_strdup( url ); @@ -353,13 +355,16 @@ open_listener( li = ch_malloc( sizeof( Listener ) ); *li = l; + Debug( LDAP_DEBUG_TRACE, "daemon: initialized %s\n", + l.sl_url, 0, 0 ); + return li; } static int sockinit(void); static int sockdestroy(void); -slapd_daemon_init(char *urls, int port, int tls_port ) +int slapd_daemon_init(char *urls, int port, int tls_port ) { int i, rc; char **u; @@ -368,6 +373,9 @@ slapd_daemon_init(char *urls, int port, int tls_port ) assert( tls_port == 0 ); #endif + Debug( LDAP_DEBUG_ARGS, "daemon_init: %s (%d/%d)\n", + urls ? urls : "", port, tls_port ); + if( rc = sockinit() ) { return rc; } @@ -390,22 +398,35 @@ slapd_daemon_init(char *urls, int port, int tls_port ) FD_ZERO( &slap_daemon.sd_writers ); if( urls == NULL ) { - urls = ch_strdup("ldap://"); + urls = "ldap:///"; } u = str2charray( urls, " " ); - if( u == NULL ) { + if( u == NULL || u[0] == NULL ) { + Debug( LDAP_DEBUG_ANY, "daemon_init: no urls (%s) provided.\n", + urls, 0, 0 ); + return -1; } - for(i = 0; u[i] == NULL; i++ ) { - /* EMPTY */ ; + for( i=0; u[i] != NULL; i++ ) { + Debug( LDAP_DEBUG_TRACE, "daemon_init: listen on %s\n", + u[i], 0, 0 ); } + if( i == 0 ) { + Debug( LDAP_DEBUG_ANY, "daemon_init: no listeners to open (%s)\n", + urls, 0, 0 ); + return -1; + } + + Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners to open...\n", + i, 0, 0 ); + slap_listeners = ch_malloc( (i+1)*sizeof(Listener *) ); - for(i = 0; u[i] == NULL; i++ ) { + for(i = 0; u[i] != NULL; i++ ) { slap_listeners[i] = open_listener( u[i], port, tls_port ); if( slap_listeners[i] == NULL ) { @@ -414,12 +435,12 @@ slapd_daemon_init(char *urls, int port, int tls_port ) } slap_listeners[i] = NULL; + Debug( LDAP_DEBUG_TRACE, "daemon_init: %d listeners opened.\n", + i, 0, 0 ); charray_free( u ); - ldap_pvt_thread_mutex_init( &slap_daemon.sd_mutex ); - - return 0; + return !i; } diff --git a/servers/slapd/main.c b/servers/slapd/main.c index a7cae58e95..d8acd705ab 100644 --- a/servers/slapd/main.c +++ b/servers/slapd/main.c @@ -320,7 +320,11 @@ int main( int argc, char **argv ) openlog( serverName, OPENLOG_OPTIONS ); #endif - slapd_daemon_init( urls, port, tls_port ); + if( slapd_daemon_init( urls, port, tls_port ) != 0 ) { + rc = 1; + SERVICE_EXIT( ERROR_SERVICE_SPECIFIC_ERROR, 16 ); + goto stop; + } #if defined(HAVE_SETUID) && defined(HAVE_SETGID) if ( username != NULL || groupname != NULL ) { -- 2.39.5