Resolve the unqualified hostname and set AI_CANONNAME to make sure that field is populated. Scan forward to the first '.' in ai_canonname, and append that value onto the unqualified hostname to get a FQDN. Then prepend that value with "cifs/" and try to get a service ticket for that principal. Signed-off-by: Jeff Layton <jlayton@xxxxxxxxx> --- cifs.upcall.c | 47 ++++++++++++++++++++++++++++++++++++++++++----- 1 files changed, 42 insertions(+), 5 deletions(-) diff --git a/cifs.upcall.c b/cifs.upcall.c index 16dec81..f560d21 100644 --- a/cifs.upcall.c +++ b/cifs.upcall.c @@ -926,12 +926,49 @@ retry_new_hostname: break; /* - * FIXME: try to guess the DNS domain name for non-FQDN's. - * - * Use getaddrinfo() to resolve the hostname of the server and - * set ai_canonname. Then use the domainname in ai_canonname - * to turn the unqualified hostname into a FQDN. + * If hostname has a '.', assume it's a FQDN, otherwise we want to + * guess the domainname. */ + if (!strchr(host, '.')) { + struct addrinfo hints; + struct addrinfo *ai; + char *domainname; + + /* + * use getaddrinfo() to resolve the hostname of the server + * and set ai_canonname. + */ + memset(&hints, 0, sizeof(hints)); + hints.ai_family = AF_UNSPEC; + hints.ai_flags = AI_CANONNAME; + rc = getaddrinfo(host, NULL, &hints, &ai); + if (rc) { + syslog(LOG_ERR, "Unable to resolve host address: %s [%s]", + host, gai_strerror(rc)); + break; + } + + /* scan forward to first '.' in ai_canonnname */ + domainname = strchr(ai->ai_canonname, '.'); + if (!domainname) { + rc = -EINVAL; + freeaddrinfo(ai); + break; + } + lowercase_string(domainname); + rc = snprintf(princ, sizeof(princ), "cifs/%s%s", + host, domainname); + freeaddrinfo(ai); + if (rc < 0 || (size_t)rc >= sizeof(princ)) { + syslog(LOG_ERR, "Problem setting hostname in string: %ld", rc); + rc = -EINVAL; + break; + } + + rc = handle_krb5_mech(oid, princ, &secblob, &sess_key, ccname); + if (!rc) + break; + } if (!try_dns || !(have & DKD_HAVE_IP)) break; -- 1.7.6.4 -- To unsubscribe from this list: send the line "unsubscribe linux-cifs" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html