summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Layton <jlayton@samba.org>2011-12-03 05:57:14 -0500
committerJeff Layton <jlayton@samba.org>2011-12-03 05:57:14 -0500
commiteb5ae2c13a52ee9645b81a9f8e37b28ea37decbb (patch)
treea3e80351d8b0bd892ae12be002c8b34b27ab89be
parentca4acee17ffc11f2771bc6a32ac0c425d53859ea (diff)
downloadcifs-utils-eb5ae2c13a52ee9645b81a9f8e37b28ea37decbb.tar.gz
cifs-utils-eb5ae2c13a52ee9645b81a9f8e37b28ea37decbb.tar.bz2
cifs-utils-eb5ae2c13a52ee9645b81a9f8e37b28ea37decbb.zip
cifs.upcall: try and guess the domain name on unqualified names
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@samba.org>
-rw-r--r--cifs.upcall.c47
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;