(krb5_sname_to_principal): use krb5_expand_hostname

git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@7762 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
Assar Westerlund
2000-01-08 08:08:03 +00:00
parent f23bd0709b
commit 6824231e69

View File

@@ -854,7 +854,10 @@ krb5_524_conv_principal(krb5_context context,
return 0; return 0;
} }
/*
* Create a principal in `ret_princ' for the service `sname' running
* on host `hostname'.
*/
krb5_error_code krb5_error_code
krb5_sname_to_principal (krb5_context context, krb5_sname_to_principal (krb5_context context,
@@ -876,32 +879,16 @@ krb5_sname_to_principal (krb5_context context,
if(sname == NULL) if(sname == NULL)
sname = "host"; sname = "host";
if(type == KRB5_NT_SRV_HST) { if(type == KRB5_NT_SRV_HST) {
int error; ret = krb5_expand_hostname (context, hostname, &host);
struct addrinfo hints, *res; if (ret)
char *host; return ret;
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;
strlwr(host); strlwr(host);
hostname = host; hostname = host;
} }
ret = krb5_get_host_realm(context, hostname, &realms); ret = krb5_get_host_realm(context, hostname, &realms);
if(ret) { if(ret)
return ret; return ret;
}
ret = krb5_make_principal(context, ret_princ, realms[0], sname, ret = krb5_make_principal(context, ret_princ, realms[0], sname,
hostname, NULL); hostname, NULL);
if(host) if(host)