From 1ec527b71267747cc3ae4d9849aa4f6362c78ea9 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Fri, 19 Jan 2001 01:20:00 +0000 Subject: [PATCH] 693. [bug] An empty lwres statement in named.conf caused the server to crash while loading. --- CHANGES | 3 + bin/named/lwresd.c | 154 ++++++++++++++++++++++++--------------------- 2 files changed, 85 insertions(+), 72 deletions(-) diff --git a/CHANGES b/CHANGES index 582ba608e5..56755ccf79 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,7 @@ + 693. [bug] An empty lwres statement in named.conf caused + the server to crash while loading. + 692. [bug] Deal with systems that have getaddrinfo() but not gai_strerror(). [RT #679] diff --git a/bin/named/lwresd.c b/bin/named/lwresd.c index 94c563fad9..053160d2bd 100644 --- a/bin/named/lwresd.c +++ b/bin/named/lwresd.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lwresd.c,v 1.28 2001/01/09 21:39:54 bwelling Exp $ */ +/* $Id: lwresd.c,v 1.29 2001/01/19 01:20:00 bwelling Exp $ */ /* * Main program for the Lightweight Resolver Daemon. @@ -672,13 +672,70 @@ ns_lwreslistener_linkcm(ns_lwreslistener_t *listener, ns_lwdclientmgr_t *cm) { ISC_LIST_APPEND(listener->cmgrs, cm, link); } +static isc_result_t +configure_listener(isc_sockaddr_t *address, ns_lwresd_t *lwresd, + isc_mem_t *mctx, ns_lwreslistenerlist_t *newlisteners) +{ + ns_lwreslistener_t *listener, *oldlistener = NULL; + char socktext[ISC_SOCKADDR_FORMATSIZE]; + isc_result_t result; + + (void)find_listener(address, &oldlistener); + listener = NULL; + result = listener_create(mctx, lwresd, &listener); + if (result != ISC_R_SUCCESS) { + isc_sockaddr_format(address, socktext, sizeof(socktext)); + isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL, + NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, + "lwres failed to configure %s: %s", + socktext, isc_result_totext(result)); + return (result); + } + + /* + * If there's already a listener, don't rebind the socket. + */ + if (oldlistener == NULL) { + result = listener_bind(listener, address); + if (result != ISC_R_SUCCESS) + return (result); + } else + listener_copysock(oldlistener, listener); + + result = listener_startclients(listener); + if (result != ISC_R_SUCCESS) { + isc_sockaddr_format(address, socktext, sizeof(socktext)); + isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL, + NS_LOGMODULE_LWRESD, ISC_LOG_WARNING, + "lwres: failed to start %s: %s", socktext, + isc_result_totext(result)); + ns_lwreslistener_detach(&listener); + return (result); + } + + if (oldlistener != NULL) { + /* + * Remove the old listener from the old list and shut it down. + */ + ISC_LIST_UNLINK(listeners, oldlistener, link); + listener_shutdown(oldlistener); + ns_lwreslistener_detach(&oldlistener); + } else { + isc_sockaddr_format(address, socktext, sizeof(socktext)); + isc_log_write(ns_g_lctx, ISC_LOGCATEGORY_GENERAL, + NS_LOGMODULE_LWRESD, ISC_LOG_NOTICE, + "lwres listening on %s", socktext); + } + + ISC_LIST_APPEND(*newlisteners, listener, link); + return (result); +} isc_result_t ns_lwresd_configure(isc_mem_t *mctx, dns_c_ctx_t *cctx) { dns_c_lwres_t *lwres = NULL; dns_c_lwreslist_t *list = NULL; ns_lwreslistener_t *listener; - ns_lwreslistener_t *oldlistener; ns_lwreslistenerlist_t newlisteners; isc_result_t result; char socktext[ISC_SOCKADDR_FORMATSIZE]; @@ -708,7 +765,6 @@ ns_lwresd_configure(isc_mem_t *mctx, dns_c_ctx_t *cctx) { lwres = dns_c_lwreslist_next(lwres)) { unsigned int i; - isc_sockaddr_t *address; ns_lwresd_t *lwresd; lwresd = NULL; @@ -716,79 +772,33 @@ ns_lwresd_configure(isc_mem_t *mctx, dns_c_ctx_t *cctx) { if (result != ISC_R_SUCCESS) return (result); - for (i = 0; i < lwres->listeners->nextidx; i++) { - address = &lwres->listeners->ips[i]; - oldlistener = NULL; - (void)find_listener(address, &oldlistener); - listener = NULL; - result = listener_create(mctx, lwresd, &listener); - if (result != ISC_R_SUCCESS) { - isc_sockaddr_format(address, socktext, - sizeof(socktext)); - isc_log_write(ns_g_lctx, - ISC_LOGCATEGORY_GENERAL, - NS_LOGMODULE_LWRESD, - ISC_LOG_WARNING, - "lwres failed to configure " - "%s: %s", - socktext, - isc_result_totext(result)); - ns_lwdmanager_detach(&lwresd); - return (result); + if (lwres->listeners == NULL) { + struct in_addr localhost; + in_port_t port; + isc_sockaddr_t address; + + port = lwresd_g_listenport; + if (port == 0) + port = LWRES_UDP_PORT; + localhost.s_addr = htonl(INADDR_LOOPBACK); + isc_sockaddr_fromin(&address, &localhost, port); + result = configure_listener(&address, lwresd, + mctx, &newlisteners); + } else { + isc_sockaddr_t *address; + for (i = 0; i < lwres->listeners->nextidx; i++) { + address = &lwres->listeners->ips[i]; + result = configure_listener(address, lwresd, + mctx, + &newlisteners); + if (result != ISC_R_SUCCESS) + break; } - - /* - * If there's already a listener, don't rebind the - * socket. - */ - if (oldlistener == NULL) { - result = listener_bind(listener, address); - if (result != ISC_R_SUCCESS) { - ns_lwdmanager_detach(&lwresd); - return (result); - } - } else - listener_copysock(oldlistener, listener); - - result = listener_startclients(listener); - if (result != ISC_R_SUCCESS) { - isc_sockaddr_format(address, socktext, - sizeof(socktext)); - isc_log_write(ns_g_lctx, - ISC_LOGCATEGORY_GENERAL, - NS_LOGMODULE_LWRESD, - ISC_LOG_WARNING, - "lwres: failed to start %s: %s", - socktext, - isc_result_totext(result)); - ns_lwreslistener_detach(&listener); - ns_lwdmanager_detach(&lwresd); - return (result); - } - - if (oldlistener != NULL) { - /* - * Remove the old listener from the old - * list and shut it down. - */ - ISC_LIST_UNLINK(listeners, oldlistener, link); - listener_shutdown(oldlistener); - ns_lwreslistener_detach(&oldlistener); - } else { - isc_sockaddr_format(address, socktext, - sizeof(socktext)); - isc_log_write(ns_g_lctx, - ISC_LOGCATEGORY_GENERAL, - NS_LOGMODULE_LWRESD, - ISC_LOG_NOTICE, - "lwres listening on %s", - socktext); - } - - ISC_LIST_APPEND(newlisteners, listener, link); } ns_lwdmanager_detach(&lwresd); + if (result != ISC_R_SUCCESS) + return (result); } /*