(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:
@@ -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,
|
||||||
@@ -869,39 +872,23 @@ krb5_sname_to_principal (krb5_context context,
|
|||||||
|
|
||||||
if(type != KRB5_NT_SRV_HST && type != KRB5_NT_UNKNOWN)
|
if(type != KRB5_NT_SRV_HST && type != KRB5_NT_UNKNOWN)
|
||||||
return KRB5_SNAME_UNSUPP_NAMETYPE;
|
return KRB5_SNAME_UNSUPP_NAMETYPE;
|
||||||
if(hostname == NULL){
|
if(hostname == NULL) {
|
||||||
gethostname(localhost, sizeof(localhost));
|
gethostname(localhost, sizeof(localhost));
|
||||||
hostname = localhost;
|
hostname = localhost;
|
||||||
}
|
}
|
||||||
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)
|
||||||
|
Reference in New Issue
Block a user