From: Todd C. Miller Date: Wed, 15 Aug 2007 13:22:06 +0000 (+0000) Subject: use getaddrinfo() instead of gethostbyname() if it is available X-Git-Tag: SUDO_1_7_0~437 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=72b36ddf50c8d89ad1d28511c38742ee846c830b;p=sudo use getaddrinfo() instead of gethostbyname() if it is available --- diff --git a/config.h.in b/config.h.in index 1f790cfa9..a94d87b2f 100644 --- a/config.h.in +++ b/config.h.in @@ -118,6 +118,9 @@ /* Define to 1 if you use the FWTK authsrv daemon. */ #undef HAVE_FWTK +/* Define to 1 if you have the `getaddrinfo' function. */ +#undef HAVE_GETADDRINFO + /* Define to 1 if you have the `getauthuid' function. (ULTRIX 4.x shadow passwords) */ #undef HAVE_GETAUTHUID diff --git a/configure b/configure index 3620d0e41..18ad293f6 100755 --- a/configure +++ b/configure @@ -14088,9 +14088,10 @@ esac + for ac_func in strchr strrchr memchr memcpy memset sysconf tzset \ strftime setrlimit initgroups getgroups fstat gettimeofday \ - setlocale + setlocale getaddrinfo do as_ac_var=`echo "ac_cv_func_$ac_func" | $as_tr_sh` echo "$as_me:$LINENO: checking for $ac_func" >&5 diff --git a/configure.in b/configure.in index 4dfd39015..3d412dceb 100644 --- a/configure.in +++ b/configure.in @@ -1675,7 +1675,7 @@ dnl Function checks dnl AC_CHECK_FUNCS(strchr strrchr memchr memcpy memset sysconf tzset \ strftime setrlimit initgroups getgroups fstat gettimeofday \ - setlocale) + setlocale getaddrinfo) if test -z "$SKIP_SETRESUID"; then AC_CHECK_FUNCS(setresuid, [SKIP_SETREUID=yes]) fi diff --git a/sudo.c b/sudo.c index 691164ef0..498f6a4f7 100644 --- a/sudo.c +++ b/sudo.c @@ -1204,17 +1204,33 @@ set_project(pw) void set_fqdn() { +#ifdef HAVE_GETADDRINFO + struct addrinfo *res0, hint; +#else struct hostent *hp; +#endif char *p; +#ifdef HAVE_GETADDRINFO + memset(&hint, 0, sizeof(hint)); + hint.ai_family = PF_UNSPEC; + hint.ai_flags = AI_CANONNAME; + if (getaddrinfo(user_host, NULL, &hint, &res0) != 0) { +#else if (!(hp = gethostbyname(user_host))) { +#endif log_error(MSG_ONLY|NO_EXIT, - "unable to lookup %s via gethostbyname()", user_host); + "unable to resolve host %s", user_host); } else { if (user_shost != user_host) efree(user_shost); efree(user_host); +#ifdef HAVE_GETADDRINFO + user_host = estrdup(res0->ai_canonname); + freeaddrinfo(res0); +#else user_host = estrdup(hp->h_name); +#endif } if ((p = strchr(user_host, '.'))) { *p = '\0';