]> git.ipfire.org Git - thirdparty/krb5.git/commitdiff
Use krb5_expand_hostname() to get admin service 349/head
authorGreg Hudson <ghudson@mit.edu>
Fri, 20 Nov 2015 00:32:11 +0000 (19:32 -0500)
committerGreg Hudson <ghudson@mit.edu>
Wed, 24 Aug 2016 16:32:23 +0000 (12:32 -0400)
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

src/lib/kadm5/alt_prof.c

index 34f8c5661d4278c3a636bbf81fd748fe64abfec4..ec6290ecc009846cdbab4529e2fb9134e76f3e2d 100644 (file)
@@ -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(&params_in, 0, sizeof(params_in));
     memset(&params_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, &params_out);
     return ret;
 }