From 6824231e69570df7cc4fcbc7c74ec49603cf0d15 Mon Sep 17 00:00:00 2001 From: Assar Westerlund Date: Sat, 8 Jan 2000 08:08:03 +0000 Subject: [PATCH] (krb5_sname_to_principal): use krb5_expand_hostname git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7762 ec53bebd-3082-4978-b11e-865c3cabbd6b --- lib/krb5/principal.c | 33 ++++++++++----------------------- 1 file changed, 10 insertions(+), 23 deletions(-) diff --git a/lib/krb5/principal.c b/lib/krb5/principal.c index adb94d2b8..bf6a69fb9 100644 --- a/lib/krb5/principal.c +++ b/lib/krb5/principal.c @@ -854,7 +854,10 @@ krb5_524_conv_principal(krb5_context context, return 0; } - +/* + * Create a principal in `ret_princ' for the service `sname' running + * on host `hostname'. + */ krb5_error_code krb5_sname_to_principal (krb5_context context, @@ -869,39 +872,23 @@ krb5_sname_to_principal (krb5_context context, if(type != KRB5_NT_SRV_HST && type != KRB5_NT_UNKNOWN) return KRB5_SNAME_UNSUPP_NAMETYPE; - if(hostname == NULL){ + if(hostname == NULL) { gethostname(localhost, sizeof(localhost)); hostname = localhost; } if(sname == NULL) sname = "host"; if(type == KRB5_NT_SRV_HST) { - int error; - struct addrinfo hints, *res; - char *host; - - memset (&hints, 0, sizeof(hints)); - hints.ai_flags = AI_CANONNAME; - - error = getaddrinfo (hostname, NULL, &hints, &res); - if (error == 0) { - if (res->ai_canonname != NULL) - host = strdup (res->ai_canonname); - else - host = strdup (hostname); - freeaddrinfo (res); - } else { - host = strdup (hostname); - } - if (host == NULL) - return ENOMEM; + ret = krb5_expand_hostname (context, hostname, &host); + if (ret) + return ret; strlwr(host); hostname = host; } ret = krb5_get_host_realm(context, hostname, &realms); - if(ret) { + if(ret) return ret; - } + ret = krb5_make_principal(context, ret_princ, realms[0], sname, hostname, NULL); if(host)