From a9c2b6881159fc80f3bcf1f71684712a9e236dcd Mon Sep 17 00:00:00 2001 From: Tom Yu Date: Thu, 8 Sep 2005 23:13:39 +0000 Subject: [PATCH] Rework logic for using res_ninit() and friends to fall back to res_init() if res_ndestroy() isn't available. ticket: 3172 tags: pullup git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@17377 dc483132-0cff-0310-8789-dd5450dbe970 --- src/ChangeLog | 5 +++++ src/aclocal.m4 | 12 ++---------- src/lib/krb5/os/ChangeLog | 8 ++++++++ src/lib/krb5/os/dnsglue.c | 30 ++++++++++++++++++++---------- 4 files changed, 35 insertions(+), 20 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index b2af644ef..d422e889c 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,8 @@ +2005-09-08 Tom Yu + + * aclocal.m4 (AC_LIBRARY_NET): Check for a few more libresolv + functions. + 2005-08-20 Ken Raeburn * aclocal.m4 (K5_AC_INIT, K5_BUGADDR): New macros. diff --git a/src/aclocal.m4 b/src/aclocal.m4 index c02426bcb..77d876aa0 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -1427,16 +1427,8 @@ AC_DEFUN(AC_LIBRARY_NET, [ # This may get us a gethostby* that doesn't respect nsswitch. AC_CHECK_LIB(resolv, main) - case $krb5_cv_host in - *-*-aix5*) - # AIX 5 has broken res_ninit due to resolv.h not having the correct - # size of struct __res_state; since we switch off of res_nsearch() - # rather than res_ninit(), pretend res_nsearch() is not available. - krb5_cv_func_res_nsearch=no - ;; - esac -_KRB5_AC_CHECK_RES_FUNCS(res_nsearch res_search ns_initparse dnl -ns_name_uncompress dn_skipname res_ndestroy) +_KRB5_AC_CHECK_RES_FUNCS(res_ninit res_nclose res_ndestroy res_nsearch dnl +ns_initparse ns_name_uncompress dn_skipname res_search) if test $krb5_cv_func_res_nsearch = no \ && test $krb5_cv_func_res_search = no; then # Attempt to link with res_search(), in case it's not prototyped. diff --git a/src/lib/krb5/os/ChangeLog b/src/lib/krb5/os/ChangeLog index 32429e756..90cb599c5 100644 --- a/src/lib/krb5/os/ChangeLog +++ b/src/lib/krb5/os/ChangeLog @@ -1,3 +1,11 @@ +2005-09-08 Tom Yu + + * dnsglue.c: Implement better logic for choosing whether to use + res_ninit(). If res_ndestroy() doesn't exist, assume that + res_ninit() is broken and use res_init(), res_search(), + etc. instead, on the theory that the OS vendor has made the older + interfaces thread-safe. + 2005-06-09 Ken Raeburn * sendto_kdc.c (service_fds): Don't create a select_state on the diff --git a/src/lib/krb5/os/dnsglue.c b/src/lib/krb5/os/dnsglue.c index 5d2db3695..03419bf77 100644 --- a/src/lib/krb5/os/dnsglue.c +++ b/src/lib/krb5/os/dnsglue.c @@ -28,6 +28,18 @@ #include "dnsglue.h" +/* + * Only use res_ninit() if there's also a res_ndestroy(), to avoid + * memory leaks (Linux & Solaris) and outright corruption (AIX 4.x, + * 5.x). While we're at it, make sure res_nsearch() is there too. + * + * In any case, it is probable that platforms having broken + * res_ninit() will have thread safety hacks for res_init() and _res. + */ +#if HAVE_RES_NINIT && HAVE_RES_NDESTROY && HAVE_RES_NSEARCH +#define USE_RES_NINIT +#endif + /* * Opaque handle */ @@ -53,7 +65,7 @@ static int initparse(struct krb5int_dns_state *); /* * krb5int_dns_init() * - * Initialize an opaue handl. Do name lookup and initial parsing of + * Initialize an opaque handle. Do name lookup and initial parsing of * reply, skipping question section. Prepare to iterate over answer * section. Returns -1 on error, 0 on success. */ @@ -61,7 +73,7 @@ int krb5int_dns_init(struct krb5int_dns_state **dsp, char *host, int nclass, int ntype) { -#if HAVE_RES_NSEARCH +#if USE_RES_NINIT struct __res_state statbuf; #endif struct krb5int_dns_state *ds; @@ -86,11 +98,13 @@ krb5int_dns_init(struct krb5int_dns_state **dsp, ds->cur_ans = 0; #endif -#if HAVE_RES_NSEARCH +#if USE_RES_NINIT ret = res_ninit(&statbuf); +#else + ret = res_init(); +#endif if (ret < 0) return -1; -#endif do { p = (ds->ansp == NULL) @@ -103,7 +117,7 @@ krb5int_dns_init(struct krb5int_dns_state **dsp, ds->ansp = p; ds->ansmax = nextincr; -#if HAVE_RES_NSEARCH +#if USE_RES_NINIT len = res_nsearch(&statbuf, host, ds->nclass, ds->ntype, ds->ansp, ds->ansmax); #else @@ -134,12 +148,8 @@ krb5int_dns_init(struct krb5int_dns_state **dsp, ret = 0; errout: -#if HAVE_RES_NSEARCH -#if HAVE_RES_NDESTROY +#if USE_RES_NINIT res_ndestroy(&statbuf); -#else - res_nclose(&statbuf); -#endif #endif if (ret < 0) { if (ds->ansp != NULL) { -- 2.26.2