From: Greg Hudson Date: Fri, 20 Nov 2015 00:32:11 +0000 (-0500) Subject: Use krb5_expand_hostname() to get admin service X-Git-Tag: krb5-1.15-beta1~73 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7b2cb7ed41e48e0fc28f106438f628f30ef86764;p=thirdparty%2Fkrb5.git Use krb5_expand_hostname() to get admin service In libkadm5's kadm5_get_admin_service_name(), use krb5_expand_hostname() instead of custom canonicalization code to canonicalize the hostname. There are some minor behavior differences; in addition to the changes listed in the previous commit, the old code did not downcase the result of the getaddrinfo() lookup, while the new code does. ticket: 8278 --- diff --git a/src/lib/kadm5/alt_prof.c b/src/lib/kadm5/alt_prof.c index 34f8c5661d..ec6290ecc0 100644 --- a/src/lib/kadm5/alt_prof.c +++ b/src/lib/kadm5/alt_prof.c @@ -836,8 +836,7 @@ kadm5_get_admin_service_name(krb5_context ctx, char *realm_in, { krb5_error_code ret; kadm5_config_params params_in, params_out; - struct addrinfo hint, *ai = NULL; - int err; + char *canonhost = NULL; memset(¶ms_in, 0, sizeof(params_in)); memset(¶ms_out, 0, sizeof(params_out)); @@ -853,25 +852,18 @@ kadm5_get_admin_service_name(krb5_context ctx, char *realm_in, goto err_params; } - memset(&hint, 0, sizeof(hint)); - hint.ai_flags = AI_CANONNAME | AI_ADDRCONFIG; - err = getaddrinfo(params_out.admin_server, NULL, &hint, &ai); - if (err != 0) { - ret = KADM5_CANT_RESOLVE; - k5_setmsg(ctx, ret, - _("Cannot resolve address of admin server \"%s\" for realm " - "\"%s\""), params_out.admin_server, realm_in); + ret = krb5_expand_hostname(ctx, params_out.admin_server, &canonhost); + if (ret) goto err_params; - } - if (strlen(ai->ai_canonname) + sizeof("kadmin/") > maxlen) { + + if (strlen(canonhost) + sizeof("kadmin/") > maxlen) { ret = ENOMEM; goto err_params; } - snprintf(admin_name, maxlen, "kadmin/%s", ai->ai_canonname); + snprintf(admin_name, maxlen, "kadmin/%s", canonhost); err_params: - if (ai != NULL) - freeaddrinfo(ai); + krb5_free_string(ctx, canonhost); kadm5_free_config_params(ctx, ¶ms_out); return ret; }