From: Tom Yu Date: Tue, 10 Apr 2007 21:51:21 +0000 (+0000) Subject: pull up r19226 from trunk X-Git-Tag: krb5-1.6.1-beta1~17 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=92f6e567d99967bea24a838b7ffefb6466d504ae;p=krb5.git pull up r19226 from trunk r19226@cathode-dark-space: raeburn | 2007-03-13 21:52:23 -0400 ticket: 5257 * kadm5_create.c: Include fake-addrinfo.h. (add_admin_princs): Use getaddrinfo instead of gethostbyname. Report the correct message on getaddrinfo errors, and return EINVAL to caller. ticket: 5257 version_fixed: 1.6.1 git-svn-id: svn://anonsvn.mit.edu/krb5/branches/krb5-1-6@19413 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/kadmin/dbutil/kadm5_create.c b/src/kadmin/dbutil/kadm5_create.c index 878300a6d..ff0d294c5 100644 --- a/src/kadmin/dbutil/kadm5_create.c +++ b/src/kadmin/dbutil/kadm5_create.c @@ -40,6 +40,8 @@ #include #include +#include "fake-addrinfo.h" + #include #include @@ -172,20 +174,33 @@ static int add_admin_princs(void *handle, krb5_context context, char *realm) krb5_error_code ret = 0; char service_name[MAXHOSTNAMELEN + 8]; char localname[MAXHOSTNAMELEN]; - struct hostent *hp; + struct addrinfo *ai, ai_hints; + int gai_error; if (gethostname(localname, MAXHOSTNAMELEN)) { ret = errno; perror("gethostname"); goto clean_and_exit; } - hp = gethostbyname(localname); - if (hp == NULL) { - ret = errno; - perror("gethostbyname"); + memset(&ai_hints, 0, sizeof(ai_hints)); + ai_hints.ai_flags = AI_CANONNAME; + gai_error = getaddrinfo(localname, (char *)NULL, &ai_hints, &ai); + if (gai_error) { + ret = EINVAL; + fprintf(stderr, "getaddrinfo(%s): %s\n", localname, + gai_strerror(gai_error)); + goto clean_and_exit; + } + if (ai->ai_canonname == NULL) { + ret = EINVAL; + fprintf(stderr, + "getaddrinfo(%s): Cannot determine canonical hostname.\n", + localname); + freeaddrinfo(ai); goto clean_and_exit; } - sprintf(service_name, "kadmin/%s", hp->h_name); + sprintf(service_name, "kadmin/%s", ai->ai_canonname); + freeaddrinfo(ai); if ((ret = add_admin_princ(handle, context, service_name, realm,